@Test public void executeWithServerAffinityWithNonZeroAffinityRetryCountWillNotSetToZero() { OpExecutorImpl opExecutor = new OpExecutorImpl(manager, queueManager, endpointManager, riTracker, -1, 10, true, cancelCriterion, mock(PoolImpl.class)); Op txSynchronizationOp = mock(TXSynchronizationOp.Impl.class); ServerLocation serverLocation = mock(ServerLocation.class); opExecutor.setAffinityRetryCount(1); opExecutor.executeWithServerAffinity(serverLocation, txSynchronizationOp); assertNotEquals(0, opExecutor.getAffinityRetryCount()); }
@Test public void executeWithServerAffinityDoesNotChangeInitialRetryCountOfZero() { OpExecutorImpl opExecutor = new OpExecutorImpl(manager, queueManager, endpointManager, riTracker, -1, 10, true, cancelCriterion, mock(PoolImpl.class)); Op txSynchronizationOp = mock(TXSynchronizationOp.Impl.class); ServerLocation serverLocation = mock(ServerLocation.class); opExecutor.setAffinityRetryCount(0); opExecutor.executeWithServerAffinity(serverLocation, txSynchronizationOp); assertEquals(0, opExecutor.getAffinityRetryCount()); }
@Test public void executeWithServerAffinityAndRetryCountGreaterThansTxRetryAttemptThrowsServerConnectivityException() { OpExecutorImpl opExecutor = spy(new OpExecutorImpl(manager, queueManager, endpointManager, riTracker, -1, 10, true, cancelCriterion, mock(PoolImpl.class))); Op txSynchronizationOp = mock(TXSynchronizationOp.Impl.class); ServerLocation serverLocation = mock(ServerLocation.class); ServerConnectivityException serverConnectivityException = new ServerConnectivityException(); doThrow(serverConnectivityException).when(opExecutor).executeOnServer(serverLocation, txSynchronizationOp, true, false); opExecutor.setupServerAffinity(true); when(((AbstractOp) txSynchronizationOp).getMessage()).thenReturn(mock(Message.class)); opExecutor.setAffinityRetryCount(opExecutor.TX_RETRY_ATTEMPT + 1); assertThatThrownBy( () -> opExecutor.executeWithServerAffinity(serverLocation, txSynchronizationOp)) .isSameAs(serverConnectivityException); }
@Test public void executeWithServerAffinityWithServerConnectivityExceptionIncrementsRetryCountAndResetsToZero() { OpExecutorImpl opExecutor = spy(new OpExecutorImpl(manager, queueManager, endpointManager, riTracker, -1, 10, true, cancelCriterion, mock(PoolImpl.class))); Op txSynchronizationOp = mock(TXSynchronizationOp.Impl.class); ServerLocation serverLocation = mock(ServerLocation.class); ServerConnectivityException serverConnectivityException = new ServerConnectivityException(); doThrow(serverConnectivityException).when(opExecutor).executeOnServer(serverLocation, txSynchronizationOp, true, false); opExecutor.setupServerAffinity(true); when(((AbstractOp) txSynchronizationOp).getMessage()).thenReturn(mock(Message.class)); opExecutor.setAffinityRetryCount(0); opExecutor.executeWithServerAffinity(serverLocation, txSynchronizationOp); verify(opExecutor, times(1)).setAffinityRetryCount(1); assertEquals(0, opExecutor.getAffinityRetryCount()); }
@Test public void testExecuteOncePerServer() throws Exception { OpExecutorImpl exec = new OpExecutorImpl(manager, queueManager, endpointManager, riTracker, -1, 10, false, cancelCriterion, null); manager.numServers = 5; try { exec.execute(new Op() { @Override public Object attempt(Connection cnx) throws Exception { throw new IOException("Something didn't work"); } @Override public boolean useThreadLocalConnection() { return true; } }); fail("Should have got an exception"); } catch (ServerConnectivityException expected) { // do nothing } assertEquals(1, borrows); assertEquals(4, exchanges); assertEquals(1, returns); assertEquals(6, invalidateConnections); assertEquals(6, serverCrashes); }
@Test public void testRetryFailedServers() throws Exception { OpExecutorImpl exec = new OpExecutorImpl(manager, queueManager, endpointManager, riTracker, 10, 10, false, cancelCriterion, null); manager.numServers = 5; try { exec.execute(new Op() { @Override public Object attempt(Connection cnx) throws Exception { throw new IOException("Something didn't work"); } @Override public boolean useThreadLocalConnection() { return true; } }); fail("Should have got an exception"); } catch (ServerConnectivityException expected) { // do nothing } assertEquals(1, borrows); assertEquals(10, exchanges); assertEquals(1, returns); assertEquals(11, invalidateConnections); assertEquals(11, serverCrashes); }
executor = new OpExecutorImpl(manager, queueManager, endpointManager, riTracker, retryAttempts, freeConnectionTimeout, threadLocalConnections, new PoolOrCacheStopper(), this); if (this.multiuserSecureModeEnabled) {
@Test public void testThreadLocalConnection() { OpExecutorImpl exec = new OpExecutorImpl(manager, queueManager, endpointManager, riTracker, 3, 10, true, cancelCriterion, null); ServerLocation server = new ServerLocation("localhost", -1);
@Test public void testExecuteOnAllQueueServers() { OpExecutorImpl exec = new OpExecutorImpl(manager, queueManager, endpointManager, riTracker, 3, 10, false, cancelCriterion, null); exec.executeOnAllQueueServers(new Op() {
@Test public void testExecute() throws Exception { OpExecutorImpl exec = new OpExecutorImpl(manager, queueManager, endpointManager, riTracker, 3, 10, false, cancelCriterion, null); Object result = exec.execute(new Op() {
@Test public void testExecuteOn() throws Exception { OpExecutorImpl exec = new OpExecutorImpl(manager, queueManager, endpointManager, riTracker, 3, 10, false, cancelCriterion, null); ServerLocation server = new ServerLocation("localhost", -1);