@Test public void testNoActions() throws Exception { setupServer(true); StorageManager storage = getStorage(); manager = liveServer.getReplicationManager(); waitForComponent(manager); Journal replicatedJournal = new ReplicatedJournal((byte) 1, new FakeJournal(), manager); replicatedJournal.appendPrepareRecord(1, new FakeData(), false); final CountDownLatch latch = new CountDownLatch(1); storage.afterCompleteOperations( new IOAsyncTask() { public void onError(final int errorCode, final String errorMessage) {} public void done() { latch.countDown(); } }); Assert.assertTrue(latch.await(1, TimeUnit.SECONDS)); Assert.assertEquals( "should be empty " + manager.getActiveTokens(), 0, manager.getActiveTokens().size()); }
public void rollback() throws Exception { synchronized (timeoutLock) { if (xid != null) { if (state != State.PREPARED && state != State.ACTIVE && state != State.ROLLBACK_ONLY) { throw new IllegalStateException("Transaction is in invalid state " + state); } } else { if (state != State.ACTIVE && state != State.ROLLBACK_ONLY) { throw new IllegalStateException("Transaction is in invalid state " + state); } } beforeRollback(); doRollback(); // We use the Callback even for non persistence // If we are using non-persistence with replication, the replication manager will have // to execute this runnable in the correct order storageManager.afterCompleteOperations( new IOAsyncTask() { public void onError(final int errorCode, final String errorMessage) { HornetQServerLogger.LOGGER.ioErrorOnTX(errorCode, errorMessage); } public void done() { afterRollback(); state = State.ROLLEDBACK; } }); } }
/** @param manager1 */ private void blockOnReplication(final StorageManager storage, final ReplicationManager manager1) throws Exception { final CountDownLatch latch = new CountDownLatch(1); storage.afterCompleteOperations( new IOAsyncTask() { public void onError(final int errorCode, final String errorMessage) {} public void done() { latch.countDown(); } }); Assert.assertTrue(latch.await(30, TimeUnit.SECONDS)); }
public void prepare() throws Exception { storageManager.readLock(); try { synchronized (timeoutLock) { if (state == State.ROLLBACK_ONLY) { if (exception != null) { // this TX will never be rolled back, // so we reset it now beforeRollback(); afterRollback(); operations.clear(); throw exception; } else { // Do nothing return; } } else if (state != State.ACTIVE) { throw new IllegalStateException("Transaction is in invalid state " + state); } if (xid == null) { throw new IllegalStateException("Cannot prepare non XA transaction"); } beforePrepare(); storageManager.prepare(id, xid); state = State.PREPARED; // We use the Callback even for non persistence // If we are using non-persistence with replication, the replication manager will have // to execute this runnable in the correct order storageManager.afterCompleteOperations( new IOAsyncTask() { public void onError(final int errorCode, final String errorMessage) { HornetQServerLogger.LOGGER.ioErrorOnTX(errorCode, errorMessage); } public void done() { afterPrepare(); } }); } } finally { storageManager.readUnLock(); } }
public void commit(final boolean onePhase) throws Exception { synchronized (timeoutLock) { if (state == State.ROLLBACK_ONLY) { rollback(); if (exception != null) { throw exception; } else { // Do nothing return; } } if (xid != null) { if (onePhase && state != State.ACTIVE || !onePhase && state != State.PREPARED) { throw new IllegalStateException("Transaction is in invalid state " + state); } } else { if (state != State.ACTIVE) { throw new IllegalStateException("Transaction is in invalid state " + state); } } beforeCommit(); doCommit(); // We use the Callback even for non persistence // If we are using non-persistence with replication, the replication manager will have // to execute this runnable in the correct order // This also will only use a different thread if there are any IO pending. // If the IO finished early by the time we got here, we won't need an executor storageManager.afterCompleteOperations( new IOAsyncTask() { public void onError(final int errorCode, final String errorMessage) { HornetQServerLogger.LOGGER.ioErrorOnTX(errorCode, errorMessage); } public void done() { afterCommit(); } }); } }
public void close(final boolean failed) { OperationContext formerCtx = storageManager.getContext(); try { storageManager.setContext(sessionContext); storageManager.afterCompleteOperations( new IOAsyncTask() { public void onError(int errorCode, String errorMessage) {} public void done() { try { doClose(failed); } catch (Exception e) { HornetQLogger.LOGGER.errorClosingSession(e); } } }); } finally { storageManager.setContext(formerCtx); } }