import org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException;
import org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException;
import org.opendaylight.controller.cluster.datastore.messages.DatastoreSnapshot;
import org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException;
import org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException;
import org.opendaylight.controller.cluster.datastore.messages.DatastoreSnapshot;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
@Test
public void testWriteTransactionWithSingleShard() throws Exception{
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
@Test
public void testWriteTransactionWithSingleShard() throws Exception{
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
- DistributedDataStore dataStore =
- setupDistributedDataStore("transactionIntegrationTest", "test-1");
+ try (DistributedDataStore dataStore =
+ setupDistributedDataStore("transactionIntegrationTest", "test-1")) {
}};
}
@Test
public void testWriteTransactionWithMultipleShards() throws Exception{
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
}};
}
@Test
public void testWriteTransactionWithMultipleShards() throws Exception{
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
- DistributedDataStore dataStore =
- setupDistributedDataStore("testWriteTransactionWithMultipleShards", "cars-1", "people-1");
-
- DOMStoreWriteTransaction writeTx = dataStore.newWriteOnlyTransaction();
- assertNotNull("newWriteOnlyTransaction returned null", writeTx);
+ try (DistributedDataStore dataStore =
+ setupDistributedDataStore("testWriteTransactionWithMultipleShards", "cars-1", "people-1")) {
- writeTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
- writeTx.write(PeopleModel.BASE_PATH, PeopleModel.emptyContainer());
+ DOMStoreWriteTransaction writeTx = dataStore.newWriteOnlyTransaction();
+ assertNotNull("newWriteOnlyTransaction returned null", writeTx);
- MapEntryNode car = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
- YangInstanceIdentifier carPath = CarsModel.newCarPath("optima");
- writeTx.write(carPath, car);
+ writeTx = dataStore.newWriteOnlyTransaction();
- MapEntryNode person = PeopleModel.newPersonEntry("jack");
- YangInstanceIdentifier personPath = PeopleModel.newPersonPath("jack");
- writeTx.write(personPath, person);
+ MapEntryNode car = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
+ YangInstanceIdentifier carPath = CarsModel.newCarPath("optima");
+ writeTx.write(carPath, car);
- doCommit(writeTx.ready());
+ MapEntryNode person = PeopleModel.newPersonEntry("jack");
+ YangInstanceIdentifier personPath = PeopleModel.newPersonPath("jack");
+ writeTx.write(personPath, person);
- Optional<NormalizedNode<?, ?>> optional = readTx.read(carPath).get(5, TimeUnit.SECONDS);
- assertEquals("isPresent", true, optional.isPresent());
- assertEquals("Data node", car, optional.get());
+ DOMStoreReadTransaction readTx = dataStore.newReadOnlyTransaction();
- optional = readTx.read(personPath).get(5, TimeUnit.SECONDS);
- assertEquals("isPresent", true, optional.isPresent());
- assertEquals("Data node", person, optional.get());
+ Optional<NormalizedNode<?, ?>> optional = readTx.read(carPath).get(5, TimeUnit.SECONDS);
+ assertEquals("isPresent", true, optional.isPresent());
+ assertEquals("Data node", car, optional.get());
+ optional = readTx.read(personPath).get(5, TimeUnit.SECONDS);
+ assertEquals("isPresent", true, optional.isPresent());
+ assertEquals("Data node", person, optional.get());
+ }
public void testReadWriteTransactionWithSingleShard() throws Exception{
System.setProperty("shard.persistent", "true");
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
public void testReadWriteTransactionWithSingleShard() throws Exception{
System.setProperty("shard.persistent", "true");
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
- DistributedDataStore dataStore =
- setupDistributedDataStore("testReadWriteTransactionWithSingleShard", "test-1");
-
- // 1. Create a read-write Tx
+ try (DistributedDataStore dataStore =
+ setupDistributedDataStore("testReadWriteTransactionWithSingleShard", "test-1")) {
- // 3. Read the data from Tx
+ YangInstanceIdentifier nodePath = TestModel.TEST_PATH;
+ NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
+ readWriteTx.write(nodePath, nodeToWrite );
- Boolean exists = readWriteTx.exists(nodePath).checkedGet(5, TimeUnit.SECONDS);
- assertEquals("exists", true, exists);
+ // 3. Read the data from Tx
- Optional<NormalizedNode<?, ?>> optional = readWriteTx.read(nodePath).get(5, TimeUnit.SECONDS);
- assertEquals("isPresent", true, optional.isPresent());
- assertEquals("Data node", nodeToWrite, optional.get());
+ Boolean exists = readWriteTx.exists(nodePath).checkedGet(5, TimeUnit.SECONDS);
+ assertEquals("exists", true, exists);
- // 4. Ready the Tx for commit
+ Optional<NormalizedNode<?, ?>> optional = readWriteTx.read(nodePath).get(5, TimeUnit.SECONDS);
+ assertEquals("isPresent", true, optional.isPresent());
+ assertEquals("Data node", nodeToWrite, optional.get());
- optional = readTx.read(nodePath).get(5, TimeUnit.SECONDS);
- assertEquals("isPresent", true, optional.isPresent());
- assertEquals("Data node", nodeToWrite, optional.get());
+ DOMStoreReadTransaction readTx = dataStore.newReadOnlyTransaction();
+ optional = readTx.read(nodePath).get(5, TimeUnit.SECONDS);
+ assertEquals("isPresent", true, optional.isPresent());
+ assertEquals("Data node", nodeToWrite, optional.get());
+ }
}};
}
@Test
public void testReadWriteTransactionWithMultipleShards() throws Exception{
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
}};
}
@Test
public void testReadWriteTransactionWithMultipleShards() throws Exception{
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
- DistributedDataStore dataStore =
- setupDistributedDataStore("testReadWriteTransactionWithMultipleShards", "cars-1", "people-1");
+ try (DistributedDataStore dataStore =
+ setupDistributedDataStore("testReadWriteTransactionWithMultipleShards", "cars-1", "people-1")) {
- DOMStoreReadWriteTransaction readWriteTx = dataStore.newReadWriteTransaction();
- assertNotNull("newReadWriteTransaction returned null", readWriteTx);
+ DOMStoreReadWriteTransaction readWriteTx = dataStore.newReadWriteTransaction();
+ assertNotNull("newReadWriteTransaction returned null", readWriteTx);
- readWriteTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
- readWriteTx.write(PeopleModel.BASE_PATH, PeopleModel.emptyContainer());
+ readWriteTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
+ readWriteTx.write(PeopleModel.BASE_PATH, PeopleModel.emptyContainer());
- readWriteTx.write(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
- readWriteTx.write(PeopleModel.PERSON_LIST_PATH, PeopleModel.newPersonMapNode());
+ readWriteTx.write(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
+ readWriteTx.write(PeopleModel.PERSON_LIST_PATH, PeopleModel.newPersonMapNode());
- MapEntryNode car = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
- YangInstanceIdentifier carPath = CarsModel.newCarPath("optima");
- readWriteTx.write(carPath, car);
+ MapEntryNode car = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
+ YangInstanceIdentifier carPath = CarsModel.newCarPath("optima");
+ readWriteTx.write(carPath, car);
- MapEntryNode person = PeopleModel.newPersonEntry("jack");
- YangInstanceIdentifier personPath = PeopleModel.newPersonPath("jack");
- readWriteTx.write(personPath, person);
+ MapEntryNode person = PeopleModel.newPersonEntry("jack");
+ YangInstanceIdentifier personPath = PeopleModel.newPersonPath("jack");
+ readWriteTx.write(personPath, person);
- Boolean exists = readWriteTx.exists(carPath).checkedGet(5, TimeUnit.SECONDS);
- assertEquals("exists", true, exists);
+ Boolean exists = readWriteTx.exists(carPath).checkedGet(5, TimeUnit.SECONDS);
+ assertEquals("exists", true, exists);
- Optional<NormalizedNode<?, ?>> optional = readWriteTx.read(carPath).get(5, TimeUnit.SECONDS);
- assertEquals("isPresent", true, optional.isPresent());
- assertEquals("Data node", car, optional.get());
+ Optional<NormalizedNode<?, ?>> optional = readWriteTx.read(carPath).get(5, TimeUnit.SECONDS);
+ assertEquals("isPresent", true, optional.isPresent());
+ assertEquals("Data node", car, optional.get());
- optional = readTx.read(carPath).get(5, TimeUnit.SECONDS);
- assertEquals("isPresent", true, optional.isPresent());
- assertEquals("Data node", car, optional.get());
+ optional = readTx.read(carPath).get(5, TimeUnit.SECONDS);
+ assertEquals("isPresent", true, optional.isPresent());
+ assertEquals("Data node", car, optional.get());
- optional = readTx.read(personPath).get(5, TimeUnit.SECONDS);
- assertEquals("isPresent", true, optional.isPresent());
- assertEquals("Data node", person, optional.get());
+ optional = readTx.read(personPath).get(5, TimeUnit.SECONDS);
+ assertEquals("isPresent", true, optional.isPresent());
+ assertEquals("Data node", person, optional.get());
}};
}
@Test
public void testSingleTransactionsWritesInQuickSuccession() throws Exception{
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
}};
}
@Test
public void testSingleTransactionsWritesInQuickSuccession() throws Exception{
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
- DistributedDataStore dataStore = setupDistributedDataStore(
- "testSingleTransactionsWritesInQuickSuccession", "cars-1");
+ try (DistributedDataStore dataStore = setupDistributedDataStore(
+ "testSingleTransactionsWritesInQuickSuccession", "cars-1")) {
- DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
- writeTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
- writeTx.write(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
- doCommit(writeTx.ready());
+ DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
+ writeTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
+ writeTx.write(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
+ doCommit(writeTx.ready());
- int nCars = 5;
- for(int i = 0; i < nCars; i++) {
- writeTx.write(CarsModel.newCarPath("car" + i),
+ int nCars = 5;
+ for(int i = 0; i < nCars; i++) {
+ writeTx.write(CarsModel.newCarPath("car" + i),
- assertEquals("isPresent", true, optional.isPresent());
- assertEquals("# cars", nCars, ((Collection<?>)optional.get().getValue()).size());
-
- cleanup(dataStore);
+ assertEquals("isPresent", true, optional.isPresent());
+ assertEquals("# cars", nCars, ((Collection<?>)optional.get().getValue()).size());
+ }
CountDownLatch blockRecoveryLatch = new CountDownLatch(1);
InMemoryJournal.addBlockReadMessagesLatch(persistentID, blockRecoveryLatch);
CountDownLatch blockRecoveryLatch = new CountDownLatch(1);
InMemoryJournal.addBlockReadMessagesLatch(persistentID, blockRecoveryLatch);
- TestModel.ID_QNAME, 1).build();
-
- final AtomicReference<DOMStoreThreePhaseCommitCohort> txCohort = new AtomicReference<>();
- final AtomicReference<Exception> caughtEx = new AtomicReference<>();
- final CountDownLatch txReady = new CountDownLatch(1);
- Thread txThread = new Thread() {
- @Override
- public void run() {
- try {
- writeTx.write(TestModel.TEST_PATH,
+ TestModel.ID_QNAME, 1).build();
+
+ final AtomicReference<DOMStoreThreePhaseCommitCohort> txCohort = new AtomicReference<>();
+ final AtomicReference<Exception> caughtEx = new AtomicReference<>();
+ final CountDownLatch txReady = new CountDownLatch(1);
+ Thread txThread = new Thread() {
+ @Override
+ public void run() {
+ try {
+ writeTx.write(TestModel.TEST_PATH,
- boolean done = Uninterruptibles.awaitUninterruptibly(txReady, 5, TimeUnit.SECONDS);
- if(caughtEx.get() != null) {
- throw caughtEx.get();
- }
-
- assertEquals("Tx ready", true, done);
+ boolean done = Uninterruptibles.awaitUninterruptibly(txReady, 5, TimeUnit.SECONDS);
+ if(caughtEx.get() != null) {
+ throw caughtEx.get();
+ }
- Optional<NormalizedNode<?, ?>> optional = readTx.read(TestModel.TEST_PATH).
- get(5, TimeUnit.SECONDS);
- assertEquals("isPresent", true, optional.isPresent());
+ DOMStoreReadTransaction readTx = dataStore.newReadOnlyTransaction();
- optional = readTx.read(TestModel.OUTER_LIST_PATH).get(5, TimeUnit.SECONDS);
- assertEquals("isPresent", true, optional.isPresent());
+ Optional<NormalizedNode<?, ?>> optional = readTx.read(TestModel.TEST_PATH).
+ get(5, TimeUnit.SECONDS);
+ assertEquals("isPresent", true, optional.isPresent());
- optional = readTx.read(listEntryPath).get(5, TimeUnit.SECONDS);
- assertEquals("isPresent", false, optional.isPresent());
+ optional = readTx.read(TestModel.OUTER_LIST_PATH).get(5, TimeUnit.SECONDS);
+ assertEquals("isPresent", true, optional.isPresent());
CountDownLatch blockRecoveryLatch = new CountDownLatch(1);
InMemoryJournal.addBlockReadMessagesLatch(persistentID, blockRecoveryLatch);
CountDownLatch blockRecoveryLatch = new CountDownLatch(1);
InMemoryJournal.addBlockReadMessagesLatch(persistentID, blockRecoveryLatch);
- final DOMStoreReadWriteTransaction readWriteTx = dataStore.newReadWriteTransaction();
- assertNotNull("newReadWriteTransaction returned null", readWriteTx);
+ final DOMStoreReadWriteTransaction readWriteTx = dataStore.newReadWriteTransaction();
+ assertNotNull("newReadWriteTransaction returned null", readWriteTx);
- final AtomicReference<CheckedFuture<Boolean, ReadFailedException>> txExistsFuture =
- new AtomicReference<>();
- final AtomicReference<CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException>>
- txReadFuture = new AtomicReference<>();
- final AtomicReference<Exception> caughtEx = new AtomicReference<>();
- final CountDownLatch txReadsDone = new CountDownLatch(1);
- Thread txThread = new Thread() {
- @Override
- public void run() {
- try {
- readWriteTx.write(TestModel.TEST_PATH,
+ final AtomicReference<CheckedFuture<Boolean, ReadFailedException>> txExistsFuture =
+ new AtomicReference<>();
+ final AtomicReference<CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException>>
+ txReadFuture = new AtomicReference<>();
+ final AtomicReference<Exception> caughtEx = new AtomicReference<>();
+ final CountDownLatch txReadsDone = new CountDownLatch(1);
+ Thread txThread = new Thread() {
+ @Override
+ public void run() {
+ try {
+ readWriteTx.write(TestModel.TEST_PATH,
- boolean done = Uninterruptibles.awaitUninterruptibly(txReadsDone, 5, TimeUnit.SECONDS);
- if(caughtEx.get() != null) {
- throw caughtEx.get();
- }
-
- assertEquals("Tx reads done", true, done);
+ boolean done = Uninterruptibles.awaitUninterruptibly(txReadsDone, 5, TimeUnit.SECONDS);
+ if(caughtEx.get() != null) {
+ throw caughtEx.get();
+ }
- assertEquals("exists", true, txExistsFuture.get().checkedGet(5, TimeUnit.SECONDS));
- assertEquals("read", true, txReadFuture.get().checkedGet(5, TimeUnit.SECONDS).isPresent());
+ // Wait for the reads to complete and verify.
+ assertEquals("exists", true, txExistsFuture.get().checkedGet(5, TimeUnit.SECONDS));
+ assertEquals("read", true, txReadFuture.get().checkedGet(5, TimeUnit.SECONDS).isPresent());
CountDownLatch blockRecoveryLatch = new CountDownLatch(1);
InMemoryJournal.addBlockReadMessagesLatch(persistentID, blockRecoveryLatch);
CountDownLatch blockRecoveryLatch = new CountDownLatch(1);
InMemoryJournal.addBlockReadMessagesLatch(persistentID, blockRecoveryLatch);
- final AtomicReference<DOMStoreThreePhaseCommitCohort> txCohort = new AtomicReference<>();
- final AtomicReference<Exception> caughtEx = new AtomicReference<>();
- final CountDownLatch txReady = new CountDownLatch(1);
- Thread txThread = new Thread() {
- @Override
- public void run() {
- try {
- writeTx.write(TestModel.TEST_PATH,
+ // 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);
+ Thread txThread = new Thread() {
+ @Override
+ public void run() {
+ try {
+ writeTx.write(TestModel.TEST_PATH,
- boolean done = Uninterruptibles.awaitUninterruptibly(txReady, 5, TimeUnit.SECONDS);
- if(caughtEx.get() != null) {
- throw caughtEx.get();
- }
+ boolean done = Uninterruptibles.awaitUninterruptibly(txReady, 5, TimeUnit.SECONDS);
+ if(caughtEx.get() != null) {
+ throw caughtEx.get();
+ }
- // Wait for the commit to complete. Since the shard never initialized, the Tx should
- // have timed out and throw an appropriate exception cause.
+ // 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);
- } catch(ExecutionException e) {
- throw e.getCause();
- } finally {
- blockRecoveryLatch.countDown();
- cleanup(dataStore);
+ try {
+ txCohort.get().canCommit().get(5, TimeUnit.SECONDS);
+ } catch(ExecutionException e) {
+ throw e.getCause();
+ } finally {
+ blockRecoveryLatch.countDown();
+ }
CountDownLatch blockRecoveryLatch = new CountDownLatch(1);
InMemoryJournal.addBlockReadMessagesLatch(persistentID, blockRecoveryLatch);
CountDownLatch blockRecoveryLatch = new CountDownLatch(1);
InMemoryJournal.addBlockReadMessagesLatch(persistentID, blockRecoveryLatch);
- final AtomicReference<CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException>>
- txReadFuture = new AtomicReference<>();
- final AtomicReference<Exception> caughtEx = new AtomicReference<>();
- final CountDownLatch txReadDone = new CountDownLatch(1);
- Thread txThread = new Thread() {
- @Override
- public void run() {
- try {
- readWriteTx.write(TestModel.TEST_PATH,
+ // Do a read on the Tx on a separate thread.
+
+ final AtomicReference<CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException>>
+ txReadFuture = new AtomicReference<>();
+ final AtomicReference<Exception> caughtEx = new AtomicReference<>();
+ final CountDownLatch txReadDone = new CountDownLatch(1);
+ Thread txThread = new Thread() {
+ @Override
+ public void run() {
+ try {
+ readWriteTx.write(TestModel.TEST_PATH,
- boolean done = Uninterruptibles.awaitUninterruptibly(txReadDone, 5, TimeUnit.SECONDS);
- if(caughtEx.get() != null) {
- throw caughtEx.get();
- }
+ boolean done = Uninterruptibles.awaitUninterruptibly(txReadDone, 5, TimeUnit.SECONDS);
+ if(caughtEx.get() != null) {
+ throw caughtEx.get();
+ }
- // Wait for the read to complete. Since the shard never initialized, the Tx should
- // have timed out and throw an appropriate exception cause.
+ // Wait for the read to complete. Since the shard never initialized, the Tx should
+ // have timed out and throw an appropriate exception cause.
- try {
- txReadFuture.get().checkedGet(5, TimeUnit.SECONDS);
- } catch(ReadFailedException e) {
- throw e.getCause();
- } finally {
- blockRecoveryLatch.countDown();
- cleanup(dataStore);
+ try {
+ txReadFuture.get().checkedGet(5, TimeUnit.SECONDS);
+ } catch(ReadFailedException e) {
+ throw e.getCause();
+ } finally {
+ blockRecoveryLatch.countDown();
+ }
datastoreContextBuilder.shardHeartbeatIntervalInMillis(100).shardElectionTimeoutFactor(1).
shardInitializationTimeout(200, TimeUnit.MILLISECONDS);
datastoreContextBuilder.shardHeartbeatIntervalInMillis(100).shardElectionTimeoutFactor(1).
shardInitializationTimeout(200, TimeUnit.MILLISECONDS);
- Object result = dataStore.getActorContext().executeOperation(dataStore.getActorContext().getShardManager(),
- new FindLocalShard(shardName, true));
- assertTrue("Expected LocalShardFound. Actual: " + result, result instanceof LocalShardFound);
+ Object result = dataStore.getActorContext().executeOperation(
+ dataStore.getActorContext().getShardManager(), new FindLocalShard(shardName, true));
+ assertTrue("Expected LocalShardFound. Actual: " + result, result instanceof LocalShardFound);
- final DOMStoreWriteTransaction writeTx = writeOnly ? dataStore.newWriteOnlyTransaction() :
- dataStore.newReadWriteTransaction();
- assertNotNull("newReadWriteTransaction returned null", writeTx);
+ try (final DOMStoreWriteTransaction writeTx = writeOnly ? dataStore.newWriteOnlyTransaction() :
+ dataStore.newReadWriteTransaction()) {
+ assertNotNull("newReadWriteTransaction returned null", writeTx);
- final AtomicReference<DOMStoreThreePhaseCommitCohort> txCohort = new AtomicReference<>();
- final AtomicReference<Exception> caughtEx = new AtomicReference<>();
- final CountDownLatch txReady = new CountDownLatch(1);
- Thread txThread = new Thread() {
- @Override
- public void run() {
- try {
- writeTx.write(TestModel.JUNK_PATH,
- ImmutableNodes.containerNode(TestModel.JUNK_QNAME));
-
- txCohort.set(writeTx.ready());
- } catch(Exception e) {
- caughtEx.set(e);
- return;
- } finally {
- txReady.countDown();
- }
- }
- };
+ final AtomicReference<DOMStoreThreePhaseCommitCohort> txCohort = new AtomicReference<>();
+ final AtomicReference<Exception> caughtEx = new AtomicReference<>();
+ final CountDownLatch txReady = new CountDownLatch(1);
+ Thread txThread = new Thread() {
+ @Override
+ public void run() {
+ try {
+ writeTx.write(TestModel.JUNK_PATH,
+ ImmutableNodes.containerNode(TestModel.JUNK_QNAME));
- assertEquals("Tx ready", true, done);
+ boolean done = Uninterruptibles.awaitUninterruptibly(txReady, 5, TimeUnit.SECONDS);
+ if(caughtEx.get() != null) {
+ throw caughtEx.get();
+ }
- // Wait for the commit to complete. Since no shard leader was elected in time, the Tx
- // should have timed out and throw an appropriate exception cause.
+ assertEquals("Tx ready", true, done);
- try {
- txCohort.get().canCommit().get(5, TimeUnit.SECONDS);
- } catch(ExecutionException e) {
- throw e.getCause();
- } finally {
- cleanup(dataStore);
+ // Wait for the commit to complete. Since no shard leader was elected in time, the Tx
+ // should have timed out and throw an appropriate exception cause.
+
+ try {
+ txCohort.get().canCommit().get(5, TimeUnit.SECONDS);
+ } catch(ExecutionException e) {
+ throw e.getCause();
+ }
+ }
@Test
public void testTransactionAbort() throws Exception{
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
@Test
public void testTransactionAbort() throws Exception{
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
- DistributedDataStore dataStore =
- setupDistributedDataStore("transactionAbortIntegrationTest", "test-1");
+ try (DistributedDataStore dataStore =
+ setupDistributedDataStore("transactionAbortIntegrationTest", "test-1")) {
- DOMStoreWriteTransaction writeTx = dataStore.newWriteOnlyTransaction();
- assertNotNull("newWriteOnlyTransaction returned null", writeTx);
+ DOMStoreWriteTransaction writeTx = dataStore.newWriteOnlyTransaction();
+ assertNotNull("newWriteOnlyTransaction returned null", writeTx);
}};
}
@Test
public void testTransactionChainWithSingleShard() throws Exception{
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
}};
}
@Test
public void testTransactionChainWithSingleShard() throws Exception{
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
- DistributedDataStore dataStore = setupDistributedDataStore("testTransactionChainWithSingleShard", "test-1");
+ try (DistributedDataStore dataStore =
+ setupDistributedDataStore("testTransactionChainWithSingleShard", "test-1")) {
- DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
- assertNotNull("newWriteOnlyTransaction returned null", writeTx);
+ DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
+ assertNotNull("newWriteOnlyTransaction returned null", writeTx);
- NormalizedNode<?, ?> testNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
- writeTx.write(TestModel.TEST_PATH, testNode);
+ NormalizedNode<?, ?> testNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
+ writeTx.write(TestModel.TEST_PATH, testNode);
- final CountDownLatch continueCommit1 = new CountDownLatch(1);
- final CountDownLatch commit1Done = new CountDownLatch(1);
- final AtomicReference<Exception> commit1Error = new AtomicReference<>();
- new Thread() {
- @Override
- public void run() {
- try {
- continueCommit1.await();
- doCommit(cohort1);
- } catch (Exception e) {
- commit1Error.set(e);
- } finally {
- commit1Done.countDown();
+ final CountDownLatch continueCommit1 = new CountDownLatch(1);
+ final CountDownLatch commit1Done = new CountDownLatch(1);
+ final AtomicReference<Exception> commit1Error = new AtomicReference<>();
+ new Thread() {
+ @Override
+ public void run() {
+ try {
+ continueCommit1.await();
+ doCommit(cohort1);
+ } catch (Exception e) {
+ commit1Error.set(e);
+ } finally {
+ commit1Done.countDown();
+ }
- DOMStoreReadTransaction readTx = txChain.newReadOnlyTransaction();
- Optional<NormalizedNode<?, ?>> optional = readTx.read(TestModel.TEST_PATH).get(5, TimeUnit.SECONDS);
- assertEquals("isPresent", true, optional.isPresent());
- assertEquals("Data node", testNode, optional.get());
+ // 5. Create a new read Tx from the chain to read and verify the data from the first
+ // Tx is visible after being readied.
- // 6. Create a new RW Tx from the chain, write more data, and ready it
+ DOMStoreReadTransaction readTx = txChain.newReadOnlyTransaction();
+ Optional<NormalizedNode<?, ?>> optional = readTx.read(TestModel.TEST_PATH).get(5, TimeUnit.SECONDS);
+ assertEquals("isPresent", true, optional.isPresent());
+ assertEquals("Data node", testNode, optional.get());
- DOMStoreReadWriteTransaction rwTx = txChain.newReadWriteTransaction();
- MapNode outerNode = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build();
- rwTx.write(TestModel.OUTER_LIST_PATH, outerNode);
+ // 6. Create a new RW Tx from the chain, write more data, and ready it
- DOMStoreThreePhaseCommitCohort cohort2 = rwTx.ready();
+ DOMStoreReadWriteTransaction rwTx = txChain.newReadWriteTransaction();
+ MapNode outerNode = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build();
+ rwTx.write(TestModel.OUTER_LIST_PATH, outerNode);
- readTx = txChain.newReadWriteTransaction();
- optional = readTx.read(TestModel.OUTER_LIST_PATH).get(5, TimeUnit.SECONDS);
- assertEquals("isPresent", true, optional.isPresent());
- assertEquals("Data node", outerNode, optional.get());
+ // 7. Create a new read Tx from the chain to read the data from the last RW Tx to
+ // verify it is visible.
- // 8. Wait for the 2 commits to complete and close the chain.
+ readTx = txChain.newReadWriteTransaction();
+ optional = readTx.read(TestModel.OUTER_LIST_PATH).get(5, TimeUnit.SECONDS);
+ assertEquals("isPresent", true, optional.isPresent());
+ assertEquals("Data node", outerNode, optional.get());
- if(commit1Error.get() != null) {
- throw commit1Error.get();
- }
+ continueCommit1.countDown();
+ Uninterruptibles.awaitUninterruptibly(commit1Done, 5, TimeUnit.SECONDS);
- readTx = dataStore.newReadOnlyTransaction();
- optional = readTx.read(TestModel.OUTER_LIST_PATH).get(5, TimeUnit.SECONDS);
- assertEquals("isPresent", true, optional.isPresent());
- assertEquals("Data node", outerNode, optional.get());
+ // 9. Create a new read Tx from the data store and verify committed data.
+ readTx = dataStore.newReadOnlyTransaction();
+ optional = readTx.read(TestModel.OUTER_LIST_PATH).get(5, TimeUnit.SECONDS);
+ assertEquals("isPresent", true, optional.isPresent());
+ assertEquals("Data node", outerNode, optional.get());
+ }
}};
}
@Test
public void testTransactionChainWithMultipleShards() throws Exception{
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
}};
}
@Test
public void testTransactionChainWithMultipleShards() throws Exception{
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
- DistributedDataStore dataStore = setupDistributedDataStore("testTransactionChainWithMultipleShards",
- "cars-1", "people-1");
+ try (DistributedDataStore dataStore = setupDistributedDataStore("testTransactionChainWithMultipleShards",
+ "cars-1", "people-1")) {
- DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
- assertNotNull("newWriteOnlyTransaction returned null", writeTx);
+ DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
+ assertNotNull("newWriteOnlyTransaction returned null", writeTx);
- writeTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
- writeTx.write(PeopleModel.BASE_PATH, PeopleModel.emptyContainer());
+ writeTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
+ writeTx.write(PeopleModel.BASE_PATH, PeopleModel.emptyContainer());
- writeTx.write(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
- writeTx.write(PeopleModel.PERSON_LIST_PATH, PeopleModel.newPersonMapNode());
+ writeTx.write(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
+ writeTx.write(PeopleModel.PERSON_LIST_PATH, PeopleModel.newPersonMapNode());
- MapEntryNode car = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
- YangInstanceIdentifier carPath = CarsModel.newCarPath("optima");
- readWriteTx.write(carPath, car);
+ MapEntryNode car = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
+ YangInstanceIdentifier carPath = CarsModel.newCarPath("optima");
+ readWriteTx.write(carPath, car);
- MapEntryNode person = PeopleModel.newPersonEntry("jack");
- YangInstanceIdentifier personPath = PeopleModel.newPersonPath("jack");
- readWriteTx.merge(personPath, person);
+ MapEntryNode person = PeopleModel.newPersonEntry("jack");
+ YangInstanceIdentifier personPath = PeopleModel.newPersonPath("jack");
+ readWriteTx.merge(personPath, person);
- Optional<NormalizedNode<?, ?>> optional = readWriteTx.read(carPath).get(5, TimeUnit.SECONDS);
- assertEquals("isPresent", true, optional.isPresent());
- assertEquals("Data node", car, optional.get());
+ Optional<NormalizedNode<?, ?>> optional = readWriteTx.read(carPath).get(5, TimeUnit.SECONDS);
+ assertEquals("isPresent", true, optional.isPresent());
+ assertEquals("Data node", car, optional.get());
- optional = readWriteTx.read(personPath).get(5, TimeUnit.SECONDS);
- assertEquals("isPresent", true, optional.isPresent());
- assertEquals("Data node", person, optional.get());
+ optional = readWriteTx.read(personPath).get(5, TimeUnit.SECONDS);
+ assertEquals("isPresent", true, optional.isPresent());
+ assertEquals("Data node", person, optional.get());
- ListenableFuture<Boolean> canCommit1 = cohort1.canCommit();
- ListenableFuture<Boolean> canCommit2 = cohort2.canCommit();
+ ListenableFuture<Boolean> canCommit1 = cohort1.canCommit();
+ ListenableFuture<Boolean> canCommit2 = cohort2.canCommit();
- doCommit(canCommit1, cohort1);
- doCommit(canCommit2, cohort2);
- doCommit(cohort3);
+ doCommit(canCommit1, cohort1);
+ doCommit(canCommit2, cohort2);
+ doCommit(cohort3);
- optional = readTx.read(carPath).get(5, TimeUnit.SECONDS);
- assertEquals("isPresent", false, optional.isPresent());
+ optional = readTx.read(carPath).get(5, TimeUnit.SECONDS);
+ assertEquals("isPresent", false, optional.isPresent());
- optional = readTx.read(personPath).get(5, TimeUnit.SECONDS);
- assertEquals("isPresent", true, optional.isPresent());
- assertEquals("Data node", person, optional.get());
-
- cleanup(dataStore);
+ optional = readTx.read(personPath).get(5, TimeUnit.SECONDS);
+ assertEquals("isPresent", true, optional.isPresent());
+ assertEquals("Data node", person, optional.get());
+ }
}};
}
@Test
public void testCreateChainedTransactionsInQuickSuccession() throws Exception{
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
}};
}
@Test
public void testCreateChainedTransactionsInQuickSuccession() throws Exception{
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
- DistributedDataStore dataStore = setupDistributedDataStore(
- "testCreateChainedTransactionsInQuickSuccession", "cars-1");
+ try (DistributedDataStore dataStore = setupDistributedDataStore(
+ "testCreateChainedTransactionsInQuickSuccession", "cars-1")) {
- TransactionChainListener listener = Mockito.mock(TransactionChainListener.class);
- DOMTransactionChain txChain = broker.createTransactionChain(listener);
+ TransactionChainListener listener = Mockito.mock(TransactionChainListener.class);
+ DOMTransactionChain txChain = broker.createTransactionChain(listener);
- DOMDataWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
- writeTx.put(LogicalDatastoreType.CONFIGURATION, CarsModel.BASE_PATH, CarsModel.emptyContainer());
- writeTx.put(LogicalDatastoreType.CONFIGURATION, CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
- futures.add(writeTx.submit());
+ DOMDataWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
+ writeTx.put(LogicalDatastoreType.CONFIGURATION, CarsModel.BASE_PATH, CarsModel.emptyContainer());
+ writeTx.put(LogicalDatastoreType.CONFIGURATION, CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
+ futures.add(writeTx.submit());
- int nCars = 100;
- for(int i = 0; i < nCars; i++) {
- DOMDataReadWriteTransaction rwTx = txChain.newReadWriteTransaction();
+ int nCars = 100;
+ for(int i = 0; i < nCars; i++) {
+ DOMDataReadWriteTransaction rwTx = txChain.newReadWriteTransaction();
- assertEquals("isPresent", true, optional.isPresent());
- assertEquals("# cars", nCars, ((Collection<?>)optional.get().getValue()).size());
-
- txChain.close();
+ assertEquals("isPresent", true, optional.isPresent());
+ assertEquals("# cars", nCars, ((Collection<?>)optional.get().getValue()).size());
}};
}
@Test
public void testCreateChainedTransactionAfterEmptyTxReadied() throws Exception{
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
}};
}
@Test
public void testCreateChainedTransactionAfterEmptyTxReadied() throws Exception{
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
- DistributedDataStore dataStore = setupDistributedDataStore(
- "testCreateChainedTransactionAfterEmptyTxReadied", "test-1");
-
- DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
+ try (DistributedDataStore dataStore = setupDistributedDataStore(
+ "testCreateChainedTransactionAfterEmptyTxReadied", "test-1")) {
- Optional<NormalizedNode<?, ?>> optional = rwTx2.read(TestModel.TEST_PATH).get(5, TimeUnit.SECONDS);
- assertEquals("isPresent", false, optional.isPresent());
+ DOMStoreReadWriteTransaction rwTx2 = txChain.newReadWriteTransaction();
}};
}
@Test
public void testCreateChainedTransactionWhenPreviousNotReady() throws Throwable {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
}};
}
@Test
public void testCreateChainedTransactionWhenPreviousNotReady() throws Throwable {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
- DistributedDataStore dataStore = setupDistributedDataStore(
- "testCreateChainedTransactionWhenPreviousNotReady", "test-1");
+ try (DistributedDataStore dataStore = setupDistributedDataStore(
+ "testCreateChainedTransactionWhenPreviousNotReady", "test-1")) {
- DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
- assertNotNull("newWriteOnlyTransaction returned null", writeTx);
+ DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
+ assertNotNull("newWriteOnlyTransaction returned null", writeTx);
}};
}
@Test
public void testCreateChainedTransactionAfterClose() throws Throwable {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
}};
}
@Test
public void testCreateChainedTransactionAfterClose() throws Throwable {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
- DistributedDataStore dataStore = setupDistributedDataStore(
- "testCreateChainedTransactionAfterClose", "test-1");
+ try (DistributedDataStore dataStore = setupDistributedDataStore(
+ "testCreateChainedTransactionAfterClose", "test-1")) {
}};
}
@Test
public void testChainWithReadOnlyTxAfterPreviousReady() throws Throwable {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
}};
}
@Test
public void testChainWithReadOnlyTxAfterPreviousReady() throws Throwable {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
- DistributedDataStore dataStore = setupDistributedDataStore(
- "testChainWithReadOnlyTxAfterPreviousReady", "test-1");
+ try (DistributedDataStore dataStore = setupDistributedDataStore(
+ "testChainWithReadOnlyTxAfterPreviousReady", "test-1")) {
- DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
- writeTx.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
- DOMStoreThreePhaseCommitCohort cohort1 = writeTx.ready();
+ DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
+ writeTx.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
+ DOMStoreThreePhaseCommitCohort cohort1 = writeTx.ready();
- CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> readFuture1 =
- txChain.newReadOnlyTransaction().read(TestModel.TEST_PATH);
+ CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> readFuture1 =
+ txChain.newReadOnlyTransaction().read(TestModel.TEST_PATH);
- CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> readFuture2 =
- txChain.newReadOnlyTransaction().read(TestModel.TEST_PATH);
+ CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> readFuture2 =
+ txChain.newReadOnlyTransaction().read(TestModel.TEST_PATH);
- DOMStoreWriteTransaction writeTx2 = txChain.newWriteOnlyTransaction();
- writeTx2.write(TestModel.OUTER_LIST_PATH,
+ DOMStoreWriteTransaction writeTx2 = txChain.newWriteOnlyTransaction();
+ writeTx2.write(TestModel.OUTER_LIST_PATH,
- assertEquals("isPresent", true, readFuture1.checkedGet(5, TimeUnit.SECONDS).isPresent());
- assertEquals("isPresent", true, readFuture2.checkedGet(5, TimeUnit.SECONDS).isPresent());
+ assertEquals("isPresent", true, readFuture1.checkedGet(5, TimeUnit.SECONDS).isPresent());
+ assertEquals("isPresent", true, readFuture2.checkedGet(5, TimeUnit.SECONDS).isPresent());
}};
}
@Test
public void testChainedTransactionFailureWithSingleShard() throws Exception{
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
}};
}
@Test
public void testChainedTransactionFailureWithSingleShard() throws Exception{
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
- DistributedDataStore dataStore = setupDistributedDataStore(
- "testChainedTransactionFailureWithSingleShard", "cars-1");
+ try (DistributedDataStore dataStore = setupDistributedDataStore(
+ "testChainedTransactionFailureWithSingleShard", "cars-1")) {
- TransactionChainListener listener = Mockito.mock(TransactionChainListener.class);
- DOMTransactionChain txChain = broker.createTransactionChain(listener);
+ TransactionChainListener listener = Mockito.mock(TransactionChainListener.class);
+ DOMTransactionChain txChain = broker.createTransactionChain(listener);
new YangInstanceIdentifier.NodeIdentifier(CarsModel.BASE_QNAME)).
withChild(ImmutableNodes.leafNode(TestModel.JUNK_QNAME, "junk")).build();
new YangInstanceIdentifier.NodeIdentifier(CarsModel.BASE_QNAME)).
withChild(ImmutableNodes.leafNode(TestModel.JUNK_QNAME, "junk")).build();
- try {
- rwTx.submit().checkedGet(5, TimeUnit.SECONDS);
- fail("Expected TransactionCommitFailedException");
- } catch (TransactionCommitFailedException e) {
- // Expected
- }
+ try {
+ rwTx.submit().checkedGet(5, TimeUnit.SECONDS);
+ fail("Expected TransactionCommitFailedException");
+ } catch (TransactionCommitFailedException e) {
+ // Expected
+ }
- verify(listener, timeout(5000)).onTransactionChainFailed(eq(txChain), eq(rwTx), any(Throwable.class));
+ verify(listener, timeout(5000)).onTransactionChainFailed(eq(txChain), eq(rwTx), any(Throwable.class));
}};
}
@Test
public void testChainedTransactionFailureWithMultipleShards() throws Exception{
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
}};
}
@Test
public void testChainedTransactionFailureWithMultipleShards() throws Exception{
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
- DistributedDataStore dataStore = setupDistributedDataStore(
- "testChainedTransactionFailureWithMultipleShards", "cars-1", "people-1");
+ try (DistributedDataStore dataStore = setupDistributedDataStore(
+ "testChainedTransactionFailureWithMultipleShards", "cars-1", "people-1")) {
- TransactionChainListener listener = Mockito.mock(TransactionChainListener.class);
- DOMTransactionChain txChain = broker.createTransactionChain(listener);
+ TransactionChainListener listener = Mockito.mock(TransactionChainListener.class);
+ DOMTransactionChain txChain = broker.createTransactionChain(listener);
- writeTx.put(LogicalDatastoreType.CONFIGURATION, PeopleModel.BASE_PATH, PeopleModel.emptyContainer());
+ writeTx.put(LogicalDatastoreType.CONFIGURATION, PeopleModel.BASE_PATH, PeopleModel.emptyContainer());
new YangInstanceIdentifier.NodeIdentifier(CarsModel.BASE_QNAME)).
withChild(ImmutableNodes.leafNode(TestModel.JUNK_QNAME, "junk")).build();
new YangInstanceIdentifier.NodeIdentifier(CarsModel.BASE_QNAME)).
withChild(ImmutableNodes.leafNode(TestModel.JUNK_QNAME, "junk")).build();
- // Note that merge will validate the data and fail but put succeeds b/c deep validation is not
- // done for put for performance reasons.
- writeTx.merge(LogicalDatastoreType.CONFIGURATION, CarsModel.BASE_PATH, invalidData);
+ // Note that merge will validate the data and fail but put succeeds b/c deep validation is not
+ // done for put for performance reasons.
+ writeTx.merge(LogicalDatastoreType.CONFIGURATION, CarsModel.BASE_PATH, invalidData);
- try {
- writeTx.submit().checkedGet(5, TimeUnit.SECONDS);
- fail("Expected TransactionCommitFailedException");
- } catch (TransactionCommitFailedException e) {
- // Expected
- }
+ try {
+ writeTx.submit().checkedGet(5, TimeUnit.SECONDS);
+ fail("Expected TransactionCommitFailedException");
+ } catch (TransactionCommitFailedException e) {
+ // Expected
+ }
- verify(listener, timeout(5000)).onTransactionChainFailed(eq(txChain), eq(writeTx), any(Throwable.class));
+ verify(listener, timeout(5000)).onTransactionChainFailed(eq(txChain), eq(writeTx), any(Throwable.class));
}};
}
@Test
public void testChangeListenerRegistration() throws Exception{
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
}};
}
@Test
public void testChangeListenerRegistration() throws Exception{
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
- DistributedDataStore dataStore =
- setupDistributedDataStore("testChangeListenerRegistration", "test-1");
+ try (DistributedDataStore dataStore =
+ setupDistributedDataStore("testChangeListenerRegistration", "test-1")) {
- ListenerRegistration<MockDataChangeListener>
- listenerReg = dataStore.registerChangeListener(TestModel.TEST_PATH, listener,
- DataChangeScope.SUBTREE);
+ ListenerRegistration<MockDataChangeListener>
+ listenerReg = dataStore.registerChangeListener(TestModel.TEST_PATH, listener,
+ DataChangeScope.SUBTREE);
- YangInstanceIdentifier listPath = YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH).
- nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1).build();
- testWriteTransaction(dataStore, listPath,
+ YangInstanceIdentifier listPath = YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH).
+ nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1).build();
+ testWriteTransaction(dataStore, listPath,
nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 2).build(),
ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 2));
nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 2).build(),
ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 2));
CarsModel.newCarEntry("optima", BigInteger.valueOf(20000L)),
CarsModel.newCarEntry("sportage", BigInteger.valueOf(30000L))));
CarsModel.newCarEntry("optima", BigInteger.valueOf(20000L)),
CarsModel.newCarEntry("sportage", BigInteger.valueOf(30000L))));
AbstractShardTest.writeToStore(dataTree, CarsModel.BASE_PATH, carsNode);
NormalizedNode<?, ?> root = AbstractShardTest.readStore(dataTree.getDataTree(),
AbstractShardTest.writeToStore(dataTree, CarsModel.BASE_PATH, carsNode);
NormalizedNode<?, ?> root = AbstractShardTest.readStore(dataTree.getDataTree(),
Snapshot carsSnapshot = Snapshot.create(SerializationUtils.serializeNormalizedNode(root),
Collections.<ReplicatedLogEntry>emptyList(), 2, 1, 2, 1, 1, "member-1");
NormalizedNode<?, ?> peopleNode = PeopleModel.create();
Snapshot carsSnapshot = Snapshot.create(SerializationUtils.serializeNormalizedNode(root),
Collections.<ReplicatedLogEntry>emptyList(), 2, 1, 2, 1, 1, "member-1");
NormalizedNode<?, ?> peopleNode = PeopleModel.create();
Snapshot peopleSnapshot = Snapshot.create(SerializationUtils.serializeNormalizedNode(root),
Collections.<ReplicatedLogEntry>emptyList(), 2, 1, 2, 1, 1, "member-1");
Snapshot peopleSnapshot = Snapshot.create(SerializationUtils.serializeNormalizedNode(root),
Collections.<ReplicatedLogEntry>emptyList(), 2, 1, 2, 1, 1, "member-1");
new DatastoreSnapshot.ShardSnapshot("people",
org.apache.commons.lang3.SerializationUtils.serialize(peopleSnapshot))));
new DatastoreSnapshot.ShardSnapshot("people",
org.apache.commons.lang3.SerializationUtils.serialize(peopleSnapshot))));
- DistributedDataStore dataStore = setupDistributedDataStore(name, "module-shards-member1.conf",
- true, "cars", "people");
+ try (DistributedDataStore dataStore = setupDistributedDataStore(name, "module-shards-member1.conf",
+ true, "cars", "people")) {
- Optional<NormalizedNode<?, ?>> optional = readTx.read(CarsModel.BASE_PATH).get(5, TimeUnit.SECONDS);
- assertEquals("isPresent", true, optional.isPresent());
- assertEquals("Data node", carsNode, optional.get());
+ Optional<NormalizedNode<?, ?>> optional = readTx.read(CarsModel.BASE_PATH).get(5, TimeUnit.SECONDS);
+ assertEquals("isPresent", true, optional.isPresent());
+ assertEquals("Data node", carsNode, optional.get());
- optional = readTx.read(PeopleModel.BASE_PATH).get(5, TimeUnit.SECONDS);
- assertEquals("isPresent", true, optional.isPresent());
- assertEquals("Data node", peopleNode, optional.get());
-
- cleanup(dataStore);
+ optional = readTx.read(PeopleModel.BASE_PATH).get(5, TimeUnit.SECONDS);
+ assertEquals("isPresent", true, optional.isPresent());
+ assertEquals("Data node", peopleNode, optional.get());
+ }