summaryrefslogtreecommitdiffstats
path: root/appc-dispatcher/appc-dispatcher-common/lock-manager-lib/lock-manager-impl/src/test/java/org/onap/appc/lockmanager/impl/sql/pessimistic/MySqlLockManagerMock.java
diff options
context:
space:
mode:
Diffstat (limited to 'appc-dispatcher/appc-dispatcher-common/lock-manager-lib/lock-manager-impl/src/test/java/org/onap/appc/lockmanager/impl/sql/pessimistic/MySqlLockManagerMock.java')
-rw-r--r--appc-dispatcher/appc-dispatcher-common/lock-manager-lib/lock-manager-impl/src/test/java/org/onap/appc/lockmanager/impl/sql/pessimistic/MySqlLockManagerMock.java200
1 files changed, 100 insertions, 100 deletions
diff --git a/appc-dispatcher/appc-dispatcher-common/lock-manager-lib/lock-manager-impl/src/test/java/org/onap/appc/lockmanager/impl/sql/pessimistic/MySqlLockManagerMock.java b/appc-dispatcher/appc-dispatcher-common/lock-manager-lib/lock-manager-impl/src/test/java/org/onap/appc/lockmanager/impl/sql/pessimistic/MySqlLockManagerMock.java
index a4bbd3406..51b1c3111 100644
--- a/appc-dispatcher/appc-dispatcher-common/lock-manager-lib/lock-manager-impl/src/test/java/org/onap/appc/lockmanager/impl/sql/pessimistic/MySqlLockManagerMock.java
+++ b/appc-dispatcher/appc-dispatcher-common/lock-manager-lib/lock-manager-impl/src/test/java/org/onap/appc/lockmanager/impl/sql/pessimistic/MySqlLockManagerMock.java
@@ -40,114 +40,114 @@ import org.onap.appc.lockmanager.impl.sql.pessimistic.MySqlLockManager;
class MySqlLockManagerMock extends MySqlLockManager implements SynchronizerReceiver {
- private final Map<String, LockRecord> locks = new HashMap<>();
- private final Lock lock = new ReentrantLock();
- private boolean useReal;
- private Synchronizer synchronizer;
+ private final Map<String, LockRecord> locks = new HashMap<>();
+ private final Lock lock = new ReentrantLock();
+ private boolean useReal;
+ private Synchronizer synchronizer;
- MySqlLockManagerMock(boolean useReal) {
- this.useReal = useReal;
- }
+ MySqlLockManagerMock(boolean useReal) {
+ this.useReal = useReal;
+ }
- @Override
- public void setSynchronizer(Synchronizer synchronizer) {
- this.synchronizer = synchronizer;
- }
+ @Override
+ public void setSynchronizer(Synchronizer synchronizer) {
+ this.synchronizer = synchronizer;
+ }
- @Override
- protected Connection openDbConnection() {
- if(useReal) {
- return super.openDbConnection();
- }
- return null;
- }
+ @Override
+ protected Connection openDbConnection() {
+ if(useReal) {
+ return super.openDbConnection();
+ }
+ return null;
+ }
- @Override
- protected void closeDbConnection(Connection connection) {
- if(useReal) {
- super.closeDbConnection(connection);
- }
- }
+ @Override
+ protected void closeDbConnection(Connection connection) {
+ if(useReal) {
+ super.closeDbConnection(connection);
+ }
+ }
- @Override
- protected LockRecord loadLockRecord(Connection connection, String resource) throws SQLException {
- LockRecord res;
- if(useReal) {
- res = super.loadLockRecord(connection, resource);
- } else {
- res = locks.get(resource);
- }
- if(synchronizer != null) {
- synchronizer.postLoadLockRecord(resource, (res == null) ? null : res.getOwner());
- }
- return res;
- }
+ @Override
+ protected LockRecord loadLockRecord(Connection connection, String resource) throws SQLException {
+ LockRecord res;
+ if(useReal) {
+ res = super.loadLockRecord(connection, resource);
+ } else {
+ res = locks.get(resource);
+ }
+ if(synchronizer != null) {
+ synchronizer.postLoadLockRecord(resource, (res == null) ? null : res.getOwner());
+ }
+ return res;
+ }
- @Override
- protected void addLockRecord(Connection connection, String resource, String owner, long timeout) throws SQLException {
- if(synchronizer != null) {
- synchronizer.preAddLockRecord(resource, owner);
- }
- try {
- if(useReal) {
- super.addLockRecord(connection, resource, owner, timeout);
- return;
- }
- LockRecord lockRecord = new LockRecord(resource);
- lockRecord.setOwner(owner);
- lockRecord.setUpdated(System.currentTimeMillis());
- lockRecord.setTimeout(timeout);
- locks.put(resource, lockRecord);
- } finally {
- if(synchronizer != null) {
- synchronizer.postAddLockRecord(resource, owner);
- }
- }
- }
+ @Override
+ protected void addLockRecord(Connection connection, String resource, String owner, long timeout) throws SQLException {
+ if(synchronizer != null) {
+ synchronizer.preAddLockRecord(resource, owner);
+ }
+ try {
+ if(useReal) {
+ super.addLockRecord(connection, resource, owner, timeout);
+ return;
+ }
+ LockRecord lockRecord = new LockRecord(resource);
+ lockRecord.setOwner(owner);
+ lockRecord.setUpdated(System.currentTimeMillis());
+ lockRecord.setTimeout(timeout);
+ locks.put(resource, lockRecord);
+ } finally {
+ if(synchronizer != null) {
+ synchronizer.postAddLockRecord(resource, owner);
+ }
+ }
+ }
- @Override
- protected void updateLockRecord(Connection connection, String resource, String owner, long timeout) throws SQLException {
- if(synchronizer != null) {
- synchronizer.preUpdateLockRecord(resource, owner);
- }
- try {
- if(useReal) {
- super.updateLockRecord(connection, resource, owner, timeout);
- return;
- }
- LockRecord lockRecord = loadLockRecord(connection, resource);
- lockRecord.setOwner(owner);
- lockRecord.setUpdated(System.currentTimeMillis());
- lockRecord.setTimeout(timeout);
- locks.put(resource, lockRecord);
- } finally {
- if(synchronizer != null) {
- synchronizer.postUpdateLockRecord(resource, owner);
- }
- }
- }
+ @Override
+ protected void updateLockRecord(Connection connection, String resource, String owner, long timeout) throws SQLException {
+ if(synchronizer != null) {
+ synchronizer.preUpdateLockRecord(resource, owner);
+ }
+ try {
+ if(useReal) {
+ super.updateLockRecord(connection, resource, owner, timeout);
+ return;
+ }
+ LockRecord lockRecord = loadLockRecord(connection, resource);
+ lockRecord.setOwner(owner);
+ lockRecord.setUpdated(System.currentTimeMillis());
+ lockRecord.setTimeout(timeout);
+ locks.put(resource, lockRecord);
+ } finally {
+ if(synchronizer != null) {
+ synchronizer.postUpdateLockRecord(resource, owner);
+ }
+ }
+ }
- @Override
- protected void enterCriticalSection(Connection connection, String resource) {
- if(useReal) {
- super.enterCriticalSection(connection, resource);
- return;
- }
- try {
- if(!lock.tryLock(criticalSectionWaitTimeoutSecs, TimeUnit.SECONDS)) {
+ @Override
+ protected void enterCriticalSection(Connection connection, String resource) {
+ if(useReal) {
+ super.enterCriticalSection(connection, resource);
+ return;
+ }
+ try {
+ if(!lock.tryLock(criticalSectionWaitTimeoutSecs, TimeUnit.SECONDS)) {
throw new LockRuntimeException("Cannot obtain critical section lock for resource [" + resource + "].");
- }
- } catch(InterruptedException e) {
- throw new LockRuntimeException("Cannot obtain critical section lock.", e);
- }
- }
+ }
+ } catch(InterruptedException e) {
+ throw new LockRuntimeException("Cannot obtain critical section lock.", e);
+ }
+ }
- @Override
- protected void leaveCriticalSection(Connection connection, String resource) {
- if(useReal) {
- super.leaveCriticalSection(connection, resource);
- return;
- }
- lock.unlock();
- }
+ @Override
+ protected void leaveCriticalSection(Connection connection, String resource) {
+ if(useReal) {
+ super.leaveCriticalSection(connection, resource);
+ return;
+ }
+ lock.unlock();
+ }
}