+ final IntegrationTestKit testKit = new IntegrationTestKit(getSystem(), datastoreContextBuilder);
+ final String testName = "testTransactionCommitFailureWithShardNotInitialized";
+ final String shardName = "test-1";
+
+ // Set the shard initialization timeout low for the test.
+ datastoreContextBuilder.shardInitializationTimeout(300, TimeUnit.MILLISECONDS);
+
+ // Setup the InMemoryJournal to block shard recovery
+ // indefinitely.
+ final String persistentID = String.format("member-1-shard-%s-%s", shardName, testName);
+ final CountDownLatch blockRecoveryLatch = new CountDownLatch(1);
+ InMemoryJournal.addBlockReadMessagesLatch(persistentID, blockRecoveryLatch);
+
+ InMemoryJournal.addEntry(persistentID, 1, "Dummy data so akka will read from persistence");
+
+ final AbstractDataStore dataStore = testKit.setupAbstractDataStore(testParameter, testName, false, shardName);
+
+ // Create the write Tx
+ final DOMStoreWriteTransaction writeTx = dataStore.newWriteOnlyTransaction();
+ assertNotNull("newReadWriteTransaction returned null", writeTx);
+
+ // Do some modifications and ready the Tx on a separate
+ // thread.
+ final AtomicReference<DOMStoreThreePhaseCommitCohort> txCohort = new AtomicReference<>();
+ final AtomicReference<Exception> caughtEx = new AtomicReference<>();
+ final CountDownLatch txReady = new CountDownLatch(1);
+ final Thread txThread = new Thread(() -> {
+ try {
+ writeTx.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
+
+ txCohort.set(writeTx.ready());
+ } catch (Exception e) {
+ caughtEx.set(e);
+ } finally {
+ txReady.countDown();
+ }
+ });
+
+ txThread.start();
+
+ // Wait for the Tx operations to complete.
+ boolean done = Uninterruptibles.awaitUninterruptibly(txReady, 5, TimeUnit.SECONDS);
+ if (caughtEx.get() != null) {
+ throw caughtEx.get();
+ }
+
+ assertTrue("Tx ready", done);
+
+ // Wait for the commit to complete. Since the shard never
+ // initialized, the Tx should
+ // have timed out and throw an appropriate exception cause.
+ try {
+ txCohort.get().canCommit().get(5, TimeUnit.SECONDS);
+ fail("Expected NotInitializedException");
+ } catch (final Exception e) {
+ final Throwable root = Throwables.getRootCause(e);
+ Throwables.throwIfUnchecked(root);
+ throw new RuntimeException(root);
+ } finally {
+ blockRecoveryLatch.countDown();
+ }
+ }
+
+ @Test(expected = NotInitializedException.class)
+ @SuppressWarnings("checkstyle:IllegalCatch")
+ public void testTransactionReadFailureWithShardNotInitialized() throws Exception {
+ final IntegrationTestKit testKit = new IntegrationTestKit(getSystem(), datastoreContextBuilder);
+ final String testName = "testTransactionReadFailureWithShardNotInitialized";
+ final String shardName = "test-1";
+
+ // Set the shard initialization timeout low for the test.
+ datastoreContextBuilder.shardInitializationTimeout(300, TimeUnit.MILLISECONDS);
+
+ // Setup the InMemoryJournal to block shard recovery
+ // indefinitely.
+ final String persistentID = String.format("member-1-shard-%s-%s", shardName, testName);
+ final CountDownLatch blockRecoveryLatch = new CountDownLatch(1);
+ InMemoryJournal.addBlockReadMessagesLatch(persistentID, blockRecoveryLatch);
+
+ InMemoryJournal.addEntry(persistentID, 1, "Dummy data so akka will read from persistence");