mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 19:42:36 +02:00
GP-2181 - removed JMockit usage from some tests (part 3)
This commit is contained in:
parent
91e5259018
commit
0a32484b5b
2 changed files with 112 additions and 86 deletions
|
@ -18,6 +18,7 @@ package ghidra.framework.data;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
|
||||
import db.DBConstants;
|
||||
import db.DBHandle;
|
||||
|
@ -38,12 +39,12 @@ import ghidra.util.task.TaskMonitorAdapter;
|
|||
* concept of starting a transaction before a change is made to the
|
||||
* domain object and ending the transaction. The transaction allows for
|
||||
* undo/redo changes.
|
||||
*
|
||||
*
|
||||
* The implementation class must also satisfy the following requirements:
|
||||
* <pre>
|
||||
*
|
||||
*
|
||||
* 1. The following constructor signature must be implemented:
|
||||
*
|
||||
*
|
||||
* **
|
||||
* * Constructs new Domain Object
|
||||
* * @param dbh a handle to an open domain object database.
|
||||
|
@ -53,16 +54,16 @@ import ghidra.util.task.TaskMonitorAdapter;
|
|||
* * UPGRADE: the database is upgraded to the latest schema as it is opened.
|
||||
* * @param monitor TaskMonitor that allows the open to be cancelled.
|
||||
* * @param consumer the object that keeping the program open.
|
||||
* *
|
||||
* *
|
||||
* * @throws IOException if an error accessing the database occurs.
|
||||
* * @throws VersionException if database version does not match implementation. UPGRADE may be possible.
|
||||
* **
|
||||
* public DomainObjectAdapterDB(DBHandle dbh, int openMode, TaskMonitor monitor, Object consumer) throws IOException, VersionException
|
||||
* public DomainObjectAdapterDB(DBHandle dbh, int openMode, TaskMonitor monitor, Object consumer) throws IOException, VersionException
|
||||
*
|
||||
* 2. The following static field must be provided:
|
||||
*
|
||||
*
|
||||
* public static final String CONTENT_TYPE
|
||||
*
|
||||
*
|
||||
* </pre>
|
||||
*/
|
||||
public abstract class DomainObjectAdapterDB extends DomainObjectAdapter
|
||||
|
@ -82,6 +83,23 @@ public abstract class DomainObjectAdapterDB extends DomainObjectAdapter
|
|||
|
||||
private AbstractTransactionManager transactionMgr;
|
||||
|
||||
//
|
||||
// This exception handler will sleep, allowing the startTransaction() method to ignore
|
||||
// the exception and then try again, since it is using a while(true) loop. This can
|
||||
// happen if clients try to start a transaction during a long running operation, such as
|
||||
// a program save.
|
||||
//
|
||||
Function<DomainObjectLockedException, Boolean> tryForeverExceptionHandler = e -> {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
catch (InterruptedException ie) {
|
||||
Msg.debug(this, "Thread interrupted while waiting for program lock: '" +
|
||||
Thread.currentThread().getName() + "'", ie);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Construct a new DomainObjectAdapterDB object.
|
||||
* If construction of this object fails, be sure to release with consumer
|
||||
|
@ -109,7 +127,7 @@ public abstract class DomainObjectAdapterDB extends DomainObjectAdapter
|
|||
|
||||
/**
|
||||
* Flush any pending database changes.
|
||||
* This method will be invoked by the transaction manager
|
||||
* This method will be invoked by the transaction manager
|
||||
* prior to closing a transaction.
|
||||
*/
|
||||
public void flushWriteCache() {
|
||||
|
@ -117,14 +135,14 @@ public abstract class DomainObjectAdapterDB extends DomainObjectAdapter
|
|||
|
||||
/**
|
||||
* Invalidate (i.e., clear) any pending database changes not yet written.
|
||||
* This method will be invoked by the transaction manager
|
||||
* This method will be invoked by the transaction manager
|
||||
* prior to aborting a transaction.
|
||||
*/
|
||||
public void invalidateWriteCache() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return array of all domain objects synchronized with a
|
||||
* Return array of all domain objects synchronized with a
|
||||
* shared transaction manager.
|
||||
* @return returns array of synchronized domain objects or
|
||||
* null if this domain object is not synchronized with others.
|
||||
|
@ -139,9 +157,9 @@ public abstract class DomainObjectAdapterDB extends DomainObjectAdapter
|
|||
|
||||
/**
|
||||
* Synchronize the specified domain object with this domain object
|
||||
* using a shared transaction manager. If either or both is already shared,
|
||||
* a transition to a single shared transaction manager will be
|
||||
* performed.
|
||||
* using a shared transaction manager. If either or both is already shared,
|
||||
* a transition to a single shared transaction manager will be
|
||||
* performed.
|
||||
* @param domainObj
|
||||
* @throws LockException if lock or open transaction is active on either
|
||||
* this or the specified domain object
|
||||
|
@ -222,7 +240,7 @@ public abstract class DomainObjectAdapterDB extends DomainObjectAdapter
|
|||
|
||||
/**
|
||||
* Returns all properties lists contained by this domain object.
|
||||
*
|
||||
*
|
||||
* @return all property lists contained by this domain object.
|
||||
*/
|
||||
@Override
|
||||
|
@ -241,7 +259,7 @@ public abstract class DomainObjectAdapterDB extends DomainObjectAdapter
|
|||
}
|
||||
|
||||
/**
|
||||
* This method can be used to perform property list alterations resulting from renamed or obsolete
|
||||
* This method can be used to perform property list alterations resulting from renamed or obsolete
|
||||
* property paths. This should only be invoked during an upgrade.
|
||||
* WARNING! Should only be called during construction of domain object
|
||||
* @see OptionsDB#performAlterations(Map)
|
||||
|
@ -317,22 +335,23 @@ public abstract class DomainObjectAdapterDB extends DomainObjectAdapter
|
|||
|
||||
@Override
|
||||
public int startTransaction(String description, AbortedTransactionListener listener) {
|
||||
int id = -1;
|
||||
while (id == -1) {
|
||||
return startTransaction(description, listener, tryForeverExceptionHandler);
|
||||
}
|
||||
|
||||
// open for testing
|
||||
int startTransaction(String description, AbortedTransactionListener listener,
|
||||
Function<DomainObjectLockedException, Boolean> exceptionHandler) {
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
id = transactionMgr.startTransaction(this, description, listener, true);
|
||||
return transactionMgr.startTransaction(this, description, listener, true);
|
||||
}
|
||||
catch (DomainObjectLockedException e) {
|
||||
// wait for lock to be removed (e.g., Save operation)
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
catch (InterruptedException e1) {
|
||||
Msg.debug(this, "Unexpected thread interrupt", e1);
|
||||
if (!exceptionHandler.apply(e)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -510,7 +529,7 @@ public abstract class DomainObjectAdapterDB extends DomainObjectAdapter
|
|||
|
||||
// TODO :( output method will cause Redo-able transactions to be cleared
|
||||
// and may cause older Undo-able transactions to be cleared.
|
||||
// Should implement transaction listener to properly maintain domain object
|
||||
// Should implement transaction listener to properly maintain domain object
|
||||
// transaction sychronization
|
||||
|
||||
}
|
||||
|
@ -520,9 +539,9 @@ public abstract class DomainObjectAdapterDB extends DomainObjectAdapter
|
|||
}
|
||||
|
||||
/**
|
||||
* This method is called before a save, saveAs, or saveToPackedFile
|
||||
* This method is called before a save, saveAs, or saveToPackedFile
|
||||
* to update common meta data
|
||||
* @throws IOException
|
||||
* @throws IOException
|
||||
*/
|
||||
protected void updateMetadata() throws IOException {
|
||||
saveMetadata();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue