@After public void closeTransactionManager() { txManager.close(); }
private void closeInternal(State newStatus) { if (checkAndSetStatus(ImmutableSet.of(State.INITIALIZING, State.READY), newStatus)) { callback.blockUntilSafeToShutdown(); executorService.shutdown(); txManager.close(); } }
@After public void after() throws Exception { txnMgr.close(); }
@Test public void shouldNotRunTaskWithRetryWithClosedTransactionManager() { txMgr.close(); assertThatThrownBy(() -> txMgr.runTaskWithRetry((TransactionTask<Void, RuntimeException>) txn -> { put(txn, "row1", "col1", "v1"); return null; })) .isInstanceOf(IllegalStateException.class) .hasMessage("Operations cannot be performed on closed TransactionManager."); }
@Test public void shouldNotRunTaskThrowOnConflictWithClosedTransactionManager() { txMgr.close(); assertThatThrownBy(() -> txMgr.runTaskThrowOnConflict((TransactionTask<Void, RuntimeException>) txn -> { put(txn, "row1", "col1", "v1"); return null; })) .isInstanceOf(IllegalStateException.class) .hasMessage("Operations cannot be performed on closed TransactionManager."); }
@Test public void shouldNotRunTaskReadOnlyWithClosedTransactionManager() { txMgr.close(); assertThatThrownBy(() -> txMgr.runTaskReadOnly((TransactionTask<Void, RuntimeException>) txn -> { put(txn, "row1", "col1", "v1"); return null; })) .isInstanceOf(IllegalStateException.class) .hasMessage("Operations cannot be performed on closed TransactionManager."); }
@Test public void closePreventsInitializationAndCallbacksEvenIfExecutorStillTicks() { manager.close(); everythingInitialized(); tickInitializingThread(); verify(mockCallback, never()).runWithRetry(any(SerializableTransactionManager.class)); assertThatThrownBy(() -> manager.runTaskWithRetry(ignore -> null)).isInstanceOf(IllegalStateException.class); assertTrue(((SerializableTransactionManager.InitializeCheckingWrapper) manager).isClosedByClose()); }
@Test public void closeShutsDownInitializingExecutorAndClosesTransactionManager() { manager.close(); assertTrue(executorService.isShutdown()); assertThatThrownBy(() -> manager.runTaskWithRetry(ignore -> null)).isInstanceOf(IllegalStateException.class); assertTrue(((SerializableTransactionManager.InitializeCheckingWrapper) manager).isClosedByClose()); }
@Test public void testStoreGetDataThrowsAfterTransactionManagerIsClosedThrows() throws Exception { txnMgr.close(); exception.expect(IllegalStateException.class); exception.expectMessage("Operations cannot be performed on closed TransactionManager."); testStore(); }
@Test public void testStoreImageThrowsAfterTransactionManagerIsClosedThrows() throws Exception { txnMgr.close(); exception.expect(IllegalStateException.class); exception.expectMessage("Operations cannot be performed on closed TransactionManager."); testStoreImage(); }
@Test public void testDeleteImageThrowsAfterTransactionManagerIsClosedThrows() throws Exception { txnMgr.close(); exception.expect(IllegalStateException.class); exception.expectMessage("Operations cannot be performed on closed TransactionManager."); testDeleteImage(); }
@Test public void testBirthdayIndexThrowsAfterTransactionManagerIsClosedThrows() throws Exception { txnMgr.close(); exception.expect(IllegalStateException.class); exception.expectMessage("Operations cannot be performed on closed TransactionManager."); testDeleteImage(); }
@Test public void runsClosingCallbackOnShutdown() throws Exception { AtlasDbConfig atlasDbConfig = ImmutableAtlasDbConfig.builder() .keyValueService(new InMemoryAtlasDbConfig()) .defaultLockTimeoutSeconds(120) .build(); Runnable callback = mock(Runnable.class); TransactionManager manager = TransactionManagers.builder() .config(atlasDbConfig) .userAgent("test") .globalMetricsRegistry(new MetricRegistry()) .globalTaggedMetricRegistry(DefaultTaggedMetricRegistry.getDefault()) .registrar(environment) .build() .serializable(); manager.registerClosingCallback(callback); manager.close(); verify(callback, times(1)).run(); }
@After public void closeTransactionManager() { txManager.close(); }
private void closeInternal(State newStatus) { if (checkAndSetStatus(ImmutableSet.of(State.INITIALIZING, State.READY), newStatus)) { callback.blockUntilSafeToShutdown(); executorService.shutdown(); txManager.close(); } }