ArgumentCaptor<Collection> candidateCapt = ArgumentCaptor.forClass(Collection.class);
IntegrationTestKit kit = new IntegrationTestKit(getSystem(), datastoreContextBuilder);
- try (AbstractDataStore dataStore = kit.setupDistributedDataStore("testSuccessfulCanCommitWithNoopPostStep",
- "test-1")) {
+ try (AbstractDataStore dataStore = kit.setupAbstractDataStore(
+ DistributedDataStore.class, "testSuccessfulCanCommitWithNoopPostStep", "test-1")) {
final ObjectRegistration<DOMDataTreeCommitCohort> cohortReg = dataStore.registerCommitCohort(TEST_ID,
cohort);
assertNotNull(cohortReg);
any(Collection.class), any(SchemaContext.class));
IntegrationTestKit kit = new IntegrationTestKit(getSystem(), datastoreContextBuilder);
- try (AbstractDataStore dataStore = kit.setupDistributedDataStore("testFailedCanCommit", "test-1")) {
+ try (AbstractDataStore dataStore = kit.setupAbstractDataStore(
+ DistributedDataStore.class, "testFailedCanCommit", "test-1")) {
dataStore.registerCommitCohort(TEST_ID, failedCohort);
IntegrationTestKit.verifyShardState(dataStore, "test-1",
any(Collection.class), any(SchemaContext.class));
IntegrationTestKit kit = new IntegrationTestKit(getSystem(), datastoreContextBuilder);
- try (AbstractDataStore dataStore = kit.setupDistributedDataStore("testCanCommitWithMultipleListEntries",
- "cars-1")) {
+ try (AbstractDataStore dataStore = kit.setupAbstractDataStore(
+ DistributedDataStore.class, "testCanCommitWithMultipleListEntries", "cars-1")) {
final ObjectRegistration<DOMDataTreeCommitCohort> cohortReg = dataStore.registerCommitCohort(
new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, CarsModel.CAR_LIST_PATH
.node(CarsModel.CAR_QNAME)), cohort);
any(Collection.class), any(SchemaContext.class));
IntegrationTestKit kit = new IntegrationTestKit(getSystem(), datastoreContextBuilder);
- try (AbstractDataStore dataStore = kit.setupDistributedDataStore("testAbortAfterCanCommit",
- "test-1", "cars-1")) {
+ try (AbstractDataStore dataStore = kit.setupAbstractDataStore(
+ DistributedDataStore.class, "testAbortAfterCanCommit", "test-1", "cars-1")) {
dataStore.registerCommitCohort(TEST_ID, cohortToAbort);
IntegrationTestKit.verifyShardState(dataStore, "test-1",
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.Assume;
+import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameter;
+import org.junit.runners.Parameterized.Parameters;
import org.mockito.Mockito;
+import org.opendaylight.controller.cluster.databroker.ClientBackedDataStore;
import org.opendaylight.controller.cluster.databroker.ConcurrentDOMDataBroker;
import org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException;
import org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException;
import org.opendaylight.controller.cluster.datastore.persisted.PayloadVersion;
import org.opendaylight.controller.cluster.datastore.persisted.ShardSnapshotState;
import org.opendaylight.controller.cluster.datastore.utils.MockDataChangeListener;
-import org.opendaylight.controller.cluster.raft.ReplicatedLogEntry;
import org.opendaylight.controller.cluster.raft.persisted.Snapshot;
import org.opendaylight.controller.cluster.raft.utils.InMemoryJournal;
import org.opendaylight.controller.cluster.raft.utils.InMemorySnapshotStore;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory;
+@RunWith(Parameterized.class)
public class DistributedDataStoreIntegrationTest {
+ @Parameters(name = "{0}")
+ public static Collection<Object[]> data() {
+ return Arrays.asList(new Object[][] {
+ { DistributedDataStore.class }, { ClientBackedDataStore.class }
+ });
+ }
+
+ @Parameter
+ public Class<? extends AbstractDataStore> testParameter;
+
private static ActorSystem system;
private final DatastoreContext.Builder datastoreContextBuilder = DatastoreContext.newBuilder()
.shardHeartbeatIntervalInMillis(100);
- @BeforeClass
- public static void setUpClass() throws IOException {
+ @Before
+ public void setUp() throws IOException {
system = ActorSystem.create("cluster-test", ConfigFactory.load().getConfig("Member1"));
Address member1Address = AddressFromURIString.parse("akka://cluster-test@127.0.0.1:2558");
Cluster.get(system).join(member1Address);
}
- @AfterClass
- public static void tearDownClass() throws IOException {
+ @After
+ public void tearDown() throws IOException {
JavaTestKit.shutdownActorSystem(system);
system = null;
}
public void testWriteTransactionWithSingleShard() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
- try (AbstractDataStore dataStore = setupDistributedDataStore("transactionIntegrationTest",
- "test-1")) {
+ try (final AbstractDataStore dataStore = setupAbstractDataStore(
+ testParameter, "transactionIntegrationTest", "test-1")) {
testWriteTransaction(dataStore, TestModel.TEST_PATH,
ImmutableNodes.containerNode(TestModel.TEST_QNAME));
public void testWriteTransactionWithMultipleShards() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
- try (AbstractDataStore dataStore = setupDistributedDataStore(
- "testWriteTransactionWithMultipleShards", "cars-1", "people-1")) {
+ try (final AbstractDataStore dataStore = setupAbstractDataStore(
+ testParameter, "testWriteTransactionWithMultipleShards", "cars-1", "people-1")) {
DOMStoreWriteTransaction writeTx = dataStore.newWriteOnlyTransaction();
assertNotNull("newWriteOnlyTransaction returned null", writeTx);
writeTx = dataStore.newWriteOnlyTransaction();
- MapEntryNode car = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
- YangInstanceIdentifier carPath = CarsModel.newCarPath("optima");
+ final MapEntryNode car = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
+ final YangInstanceIdentifier carPath = CarsModel.newCarPath("optima");
writeTx.write(carPath, car);
- MapEntryNode person = PeopleModel.newPersonEntry("jack");
- YangInstanceIdentifier personPath = PeopleModel.newPersonPath("jack");
+ final MapEntryNode person = PeopleModel.newPersonEntry("jack");
+ final YangInstanceIdentifier personPath = PeopleModel.newPersonPath("jack");
writeTx.write(personPath, person);
doCommit(writeTx.ready());
// Verify the data in the store
-
- DOMStoreReadTransaction readTx = dataStore.newReadOnlyTransaction();
+ final DOMStoreReadTransaction readTx = dataStore.newReadOnlyTransaction();
Optional<NormalizedNode<?, ?>> optional = readTx.read(carPath).get(5, TimeUnit.SECONDS);
assertEquals("isPresent", true, optional.isPresent());
public void testReadWriteTransactionWithSingleShard() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
- try (AbstractDataStore dataStore = setupDistributedDataStore(
- "testReadWriteTransactionWithSingleShard", "test-1")) {
+ try (final AbstractDataStore dataStore = setupAbstractDataStore(
+ testParameter, "testReadWriteTransactionWithSingleShard", "test-1")) {
// 1. Create a read-write Tx
-
- DOMStoreReadWriteTransaction readWriteTx = dataStore.newReadWriteTransaction();
+ final DOMStoreReadWriteTransaction readWriteTx = dataStore.newReadWriteTransaction();
assertNotNull("newReadWriteTransaction returned null", readWriteTx);
// 2. Write some data
-
- YangInstanceIdentifier nodePath = TestModel.TEST_PATH;
- NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
+ final YangInstanceIdentifier nodePath = TestModel.TEST_PATH;
+ final NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
readWriteTx.write(nodePath, nodeToWrite);
// 3. Read the data from Tx
-
- Boolean exists = readWriteTx.exists(nodePath).checkedGet(5, TimeUnit.SECONDS);
+ final Boolean exists = readWriteTx.exists(nodePath).checkedGet(5, TimeUnit.SECONDS);
assertEquals("exists", true, exists);
Optional<NormalizedNode<?, ?>> optional = readWriteTx.read(nodePath).get(5, TimeUnit.SECONDS);
assertEquals("Data node", nodeToWrite, optional.get());
// 4. Ready the Tx for commit
-
- DOMStoreThreePhaseCommitCohort cohort = readWriteTx.ready();
+ final DOMStoreThreePhaseCommitCohort cohort = readWriteTx.ready();
// 5. Commit the Tx
-
doCommit(cohort);
// 6. Verify the data in the store
-
- DOMStoreReadTransaction readTx = dataStore.newReadOnlyTransaction();
+ final DOMStoreReadTransaction readTx = dataStore.newReadOnlyTransaction();
optional = readTx.read(nodePath).get(5, TimeUnit.SECONDS);
assertEquals("isPresent", true, optional.isPresent());
public void testReadWriteTransactionWithMultipleShards() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
- try (AbstractDataStore dataStore = setupDistributedDataStore(
- "testReadWriteTransactionWithMultipleShards", "cars-1", "people-1")) {
+ try (final AbstractDataStore dataStore = setupAbstractDataStore(
+ testParameter, "testReadWriteTransactionWithMultipleShards", "cars-1", "people-1")) {
DOMStoreReadWriteTransaction readWriteTx = dataStore.newReadWriteTransaction();
assertNotNull("newReadWriteTransaction returned null", readWriteTx);
readWriteTx = dataStore.newReadWriteTransaction();
- MapEntryNode car = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
- YangInstanceIdentifier carPath = CarsModel.newCarPath("optima");
+ final MapEntryNode car = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
+ final YangInstanceIdentifier carPath = CarsModel.newCarPath("optima");
readWriteTx.write(carPath, car);
- MapEntryNode person = PeopleModel.newPersonEntry("jack");
- YangInstanceIdentifier personPath = PeopleModel.newPersonPath("jack");
+ final MapEntryNode person = PeopleModel.newPersonEntry("jack");
+ final YangInstanceIdentifier personPath = PeopleModel.newPersonPath("jack");
readWriteTx.write(personPath, person);
- Boolean exists = readWriteTx.exists(carPath).checkedGet(5, TimeUnit.SECONDS);
+ final Boolean exists = readWriteTx.exists(carPath).checkedGet(5, TimeUnit.SECONDS);
assertEquals("exists", true, exists);
Optional<NormalizedNode<?, ?>> optional = readWriteTx.read(carPath).get(5, TimeUnit.SECONDS);
doCommit(readWriteTx.ready());
// Verify the data in the store
-
DOMStoreReadTransaction readTx = dataStore.newReadOnlyTransaction();
optional = readTx.read(carPath).get(5, TimeUnit.SECONDS);
public void testSingleTransactionsWritesInQuickSuccession() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
- try (AbstractDataStore dataStore = setupDistributedDataStore(
- "testSingleTransactionsWritesInQuickSuccession", "cars-1")) {
+ try (final AbstractDataStore dataStore = setupAbstractDataStore(
+ testParameter, "testSingleTransactionsWritesInQuickSuccession", "cars-1")) {
- DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
+ final DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
writeTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
doCommit(writeTx.ready());
- Optional<NormalizedNode<?, ?>> optional = txChain.newReadOnlyTransaction()
+ final Optional<NormalizedNode<?, ?>> optional = txChain.newReadOnlyTransaction()
.read(CarsModel.CAR_LIST_PATH).get(5, TimeUnit.SECONDS);
assertEquals("isPresent", true, optional.isPresent());
assertEquals("# cars", numCars, ((Collection<?>) optional.get().getValue()).size());
throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
- String shardName = "test-1";
+ final String shardName = "test-1";
// Setup the InMemoryJournal to block shard recovery to ensure
// the shard isn't
// initialized until we create and submit the write the Tx.
- String persistentID = String.format("member-1-shard-%s-%s", shardName, testName);
- CountDownLatch blockRecoveryLatch = new CountDownLatch(1);
+ final String persistentID = String.format("member-1-shard-%s-%s", shardName, testName);
+ final CountDownLatch blockRecoveryLatch = new CountDownLatch(1);
InMemoryJournal.addBlockReadMessagesLatch(persistentID, blockRecoveryLatch);
- try (AbstractDataStore dataStore = setupDistributedDataStore(testName, false, shardName)) {
+ try (final AbstractDataStore dataStore = setupAbstractDataStore(
+ testParameter, testName, false, shardName)) {
// Create the write Tx
-
final DOMStoreWriteTransaction writeTx = writeOnly ? dataStore.newWriteOnlyTransaction()
: dataStore.newReadWriteTransaction();
assertNotNull("newReadWriteTransaction returned null", writeTx);
// Do some modification operations and ready the Tx on a
// separate thread.
-
final YangInstanceIdentifier listEntryPath = YangInstanceIdentifier
.builder(TestModel.OUTER_LIST_PATH)
.nodeWithKey(TestModel.OUTER_LIST_QNAME, 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() {
+ final Thread txThread = new Thread() {
@Override
public void run() {
try {
txCohort.set(writeTx.ready());
} catch (Exception e) {
caughtEx.set(e);
- return;
} finally {
txReady.countDown();
}
txThread.start();
// Wait for the Tx operations to complete.
-
- boolean done = Uninterruptibles.awaitUninterruptibly(txReady, 5, TimeUnit.SECONDS);
+ final boolean done = Uninterruptibles.awaitUninterruptibly(txReady, 5, TimeUnit.SECONDS);
if (caughtEx.get() != null) {
throw caughtEx.get();
}
// At this point the Tx operations should be waiting for the
// shard to initialize so
// trigger the latch to let the shard recovery to continue.
-
blockRecoveryLatch.countDown();
// Wait for the Tx commit to complete.
-
doCommit(txCohort.get());
// Verify the data in the store
-
- DOMStoreReadTransaction readTx = dataStore.newReadOnlyTransaction();
+ final DOMStoreReadTransaction readTx = dataStore.newReadOnlyTransaction();
Optional<NormalizedNode<?, ?>> optional = readTx.read(TestModel.TEST_PATH).get(5, TimeUnit.SECONDS);
assertEquals("isPresent", true, optional.isPresent());
public void testTransactionReadsWithShardNotInitiallyReady() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
- String testName = "testTransactionReadsWithShardNotInitiallyReady";
- String shardName = "test-1";
+ final String testName = "testTransactionReadsWithShardNotInitiallyReady";
+ final String shardName = "test-1";
// Setup the InMemoryJournal to block shard recovery to ensure
// the shard isn't
// initialized until we create the Tx.
- String persistentID = String.format("member-1-shard-%s-%s", shardName, testName);
- CountDownLatch blockRecoveryLatch = new CountDownLatch(1);
+ final String persistentID = String.format("member-1-shard-%s-%s", shardName, testName);
+ final CountDownLatch blockRecoveryLatch = new CountDownLatch(1);
InMemoryJournal.addBlockReadMessagesLatch(persistentID, blockRecoveryLatch);
- try (AbstractDataStore dataStore = setupDistributedDataStore(testName, false, shardName)) {
+ try (final AbstractDataStore dataStore = setupAbstractDataStore(
+ testParameter, testName, false, shardName)) {
// Create the read-write Tx
-
final DOMStoreReadWriteTransaction readWriteTx = dataStore.newReadWriteTransaction();
assertNotNull("newReadWriteTransaction returned null", readWriteTx);
// Do some reads on the Tx on a separate thread.
-
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() {
+ final Thread txThread = new Thread() {
@Override
public void run() {
try {
txReadFuture.set(readWriteTx.read(TestModel.TEST_PATH));
} catch (Exception e) {
caughtEx.set(e);
- return;
} finally {
txReadsDone.countDown();
}
txThread.start();
// Wait for the Tx operations to complete.
-
boolean done = Uninterruptibles.awaitUninterruptibly(txReadsDone, 5, TimeUnit.SECONDS);
if (caughtEx.get() != null) {
throw caughtEx.get();
// At this point the Tx operations should be waiting for the
// shard to initialize so
// trigger the latch to let the shard recovery to continue.
-
blockRecoveryLatch.countDown();
// 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());
public void testTransactionCommitFailureWithShardNotInitialized() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
- String testName = "testTransactionCommitFailureWithShardNotInitialized";
- String shardName = "test-1";
+ 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.
-
- String persistentID = String.format("member-1-shard-%s-%s", shardName, testName);
- CountDownLatch blockRecoveryLatch = new CountDownLatch(1);
+ 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");
- try (AbstractDataStore dataStore = setupDistributedDataStore(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);
- Thread txThread = new Thread() {
- @Override
- public void run() {
- try {
- writeTx.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
-
- txCohort.set(writeTx.ready());
- } catch (Exception e) {
- caughtEx.set(e);
- return;
- } finally {
- txReady.countDown();
- }
- }
- };
+ final AbstractDataStore dataStore =
+ setupAbstractDataStore(testParameter, testName, false, shardName);
- txThread.start();
+ // Create the write Tx
+ final DOMStoreWriteTransaction writeTx = dataStore.newWriteOnlyTransaction();
+ assertNotNull("newReadWriteTransaction returned null", writeTx);
- // Wait for the Tx operations to complete.
+ // 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));
- boolean done = Uninterruptibles.awaitUninterruptibly(txReady, 5, TimeUnit.SECONDS);
- if (caughtEx.get() != null) {
- throw caughtEx.get();
+ txCohort.set(writeTx.ready());
+ } catch (Exception e) {
+ caughtEx.set(e);
+ } finally {
+ txReady.countDown();
}
+ });
- assertEquals("Tx ready", true, done);
+ txThread.start();
- // 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 Tx operations to complete.
+ boolean done = Uninterruptibles.awaitUninterruptibly(txReady, 5, TimeUnit.SECONDS);
+ if (caughtEx.get() != null) {
+ throw caughtEx.get();
+ }
- try {
- txCohort.get().canCommit().get(5, TimeUnit.SECONDS);
- } catch (ExecutionException e) {
- Throwables.propagateIfInstanceOf(e.getCause(), Exception.class);
- Throwables.propagate(e.getCause());
- } finally {
- blockRecoveryLatch.countDown();
- }
+ assertEquals("Tx ready", true, 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) {
+ Throwables.propagate(Throwables.getRootCause(e));
+ } finally {
+ blockRecoveryLatch.countDown();
}
}
};
public void testTransactionReadFailureWithShardNotInitialized() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
- String testName = "testTransactionReadFailureWithShardNotInitialized";
- String shardName = "test-1";
+ 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.
-
- String persistentID = String.format("member-1-shard-%s-%s", shardName, testName);
- CountDownLatch blockRecoveryLatch = new CountDownLatch(1);
+ 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");
- try (AbstractDataStore dataStore = setupDistributedDataStore(testName, false, shardName)) {
+ try (final AbstractDataStore dataStore = setupAbstractDataStore(
+ testParameter, testName, false, shardName)) {
// Create the read-write Tx
-
final DOMStoreReadWriteTransaction readWriteTx = dataStore.newReadWriteTransaction();
assertNotNull("newReadWriteTransaction returned null", readWriteTx);
// 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,
- ImmutableNodes.containerNode(TestModel.TEST_QNAME));
+ final Thread txThread = new Thread(() -> {
+ try {
+ readWriteTx.write(TestModel.TEST_PATH,
+ ImmutableNodes.containerNode(TestModel.TEST_QNAME));
- txReadFuture.set(readWriteTx.read(TestModel.TEST_PATH));
+ txReadFuture.set(readWriteTx.read(TestModel.TEST_PATH));
- readWriteTx.close();
- } catch (Exception e) {
- caughtEx.set(e);
- return;
- } finally {
- txReadDone.countDown();
- }
+ readWriteTx.close();
+ } catch (Exception e) {
+ caughtEx.set(e);
+ } finally {
+ txReadDone.countDown();
}
- };
+ });
txThread.start();
// Wait for the Tx operations to complete.
-
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.
-
try {
txReadFuture.get().checkedGet(5, TimeUnit.SECONDS);
- } catch (ReadFailedException e) {
- Throwables.propagateIfInstanceOf(e.getCause(), Exception.class);
- Throwables.propagate(e.getCause());
+ fail("Expected NotInitializedException");
+ } catch (final ReadFailedException e) {
+ Throwables.propagate(Throwables.getRootCause(e));
} finally {
blockRecoveryLatch.countDown();
}
throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
- String shardName = "default";
+ final String shardName = "default";
// We don't want the shard to become the leader so prevent shard
// elections.
datastoreContextBuilder.shardHeartbeatIntervalInMillis(100).shardElectionTimeoutFactor(1)
.shardInitializationTimeout(200, TimeUnit.MILLISECONDS);
- try (AbstractDataStore dataStore = setupDistributedDataStore(testName, false, shardName)) {
+ try (final AbstractDataStore dataStore = setupAbstractDataStore(
+ testParameter, testName, false, shardName)) {
- Object result = dataStore.getActorContext().executeOperation(
+ final Object result = dataStore.getActorContext().executeOperation(
dataStore.getActorContext().getShardManager(), new FindLocalShard(shardName, true));
assertTrue("Expected LocalShardFound. Actual: " + result, result instanceof LocalShardFound);
// Create the write Tx.
-
- try (DOMStoreWriteTransaction writeTx = writeOnly ? dataStore.newWriteOnlyTransaction()
+ try (final DOMStoreWriteTransaction writeTx = writeOnly ? dataStore.newWriteOnlyTransaction()
: dataStore.newReadWriteTransaction()) {
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);
- 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 Thread txThread = new Thread(() -> {
+ try {
+ writeTx.write(TestModel.JUNK_PATH,
+ ImmutableNodes.containerNode(TestModel.JUNK_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();
// 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) {
- Throwables.propagateIfInstanceOf(e.getCause(), Exception.class);
- Throwables.propagate(e.getCause());
+ fail("Expected NoShardLeaderException");
+ } catch (final ExecutionException e) {
+ Throwables.propagate(Throwables.getRootCause(e));
}
}
}
public void testTransactionAbort() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
- try (AbstractDataStore dataStore = setupDistributedDataStore("transactionAbortIntegrationTest",
- "test-1")) {
+ try (final AbstractDataStore dataStore = setupAbstractDataStore(
+ testParameter, "transactionAbortIntegrationTest", "test-1")) {
- DOMStoreWriteTransaction writeTx = dataStore.newWriteOnlyTransaction();
+ final DOMStoreWriteTransaction writeTx = dataStore.newWriteOnlyTransaction();
assertNotNull("newWriteOnlyTransaction returned null", writeTx);
writeTx.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
- DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
+ final DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
cohort.canCommit().get(5, TimeUnit.SECONDS);
public void testTransactionChainWithSingleShard() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
- try (AbstractDataStore dataStore = setupDistributedDataStore("testTransactionChainWithSingleShard",
- "test-1")) {
+ try (final AbstractDataStore dataStore = setupAbstractDataStore(
+ testParameter, "testTransactionChainWithSingleShard", "test-1")) {
// 1. Create a Tx chain and write-only Tx
+ final DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
- DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
-
- DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
+ final DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
assertNotNull("newWriteOnlyTransaction returned null", writeTx);
// 2. Write some data
-
- NormalizedNode<?, ?> testNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
+ final NormalizedNode<?, ?> testNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
writeTx.write(TestModel.TEST_PATH, testNode);
// 3. Ready the Tx for commit
-
final DOMStoreThreePhaseCommitCohort cohort1 = writeTx.ready();
// 4. Commit the Tx on another thread that first waits for
// the second read Tx.
-
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();
- }
+ new Thread(() -> {
+ try {
+ continueCommit1.await();
+ doCommit(cohort1);
+ } catch (Exception e) {
+ commit1Error.set(e);
+ } finally {
+ commit1Done.countDown();
}
- }.start();
+ }).start();
// 5. Create a new read Tx from the chain to read and verify
// the data from the first
// Tx is visible after being readied.
-
DOMStoreReadTransaction readTx = txChain.newReadOnlyTransaction();
Optional<NormalizedNode<?, ?>> optional = readTx.read(TestModel.TEST_PATH).get(5, TimeUnit.SECONDS);
assertEquals("isPresent", true, optional.isPresent());
// 6. Create a new RW Tx from the chain, write more data,
// and ready it
-
- DOMStoreReadWriteTransaction rwTx = txChain.newReadWriteTransaction();
- MapNode outerNode = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build();
+ final DOMStoreReadWriteTransaction rwTx = txChain.newReadWriteTransaction();
+ final MapNode outerNode = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build();
rwTx.write(TestModel.OUTER_LIST_PATH, outerNode);
final DOMStoreThreePhaseCommitCohort cohort2 = rwTx.ready();
// 7. Create a new read Tx from the chain to read the data
// from the last RW Tx to
// verify it is visible.
-
readTx = txChain.newReadWriteTransaction();
optional = readTx.read(TestModel.OUTER_LIST_PATH).get(5, TimeUnit.SECONDS);
assertEquals("isPresent", true, optional.isPresent());
// 8. Wait for the 2 commits to complete and close the
// chain.
-
continueCommit1.countDown();
Uninterruptibles.awaitUninterruptibly(commit1Done, 5, TimeUnit.SECONDS);
// 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());
public void testTransactionChainWithMultipleShards() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
- try (AbstractDataStore dataStore = setupDistributedDataStore(
- "testTransactionChainWithMultipleShards", "cars-1", "people-1")) {
+ try (final AbstractDataStore dataStore = setupAbstractDataStore(
+ testParameter, "testTransactionChainWithMultipleShards", "cars-1", "people-1")) {
- DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
+ final DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
assertNotNull("newWriteOnlyTransaction returned null", writeTx);
final DOMStoreThreePhaseCommitCohort cohort1 = writeTx.ready();
- DOMStoreReadWriteTransaction readWriteTx = txChain.newReadWriteTransaction();
+ final DOMStoreReadWriteTransaction readWriteTx = txChain.newReadWriteTransaction();
- MapEntryNode car = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
- YangInstanceIdentifier carPath = CarsModel.newCarPath("optima");
+ final MapEntryNode car = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
+ final YangInstanceIdentifier carPath = CarsModel.newCarPath("optima");
readWriteTx.write(carPath, car);
- MapEntryNode person = PeopleModel.newPersonEntry("jack");
- YangInstanceIdentifier personPath = PeopleModel.newPersonPath("jack");
+ final MapEntryNode person = PeopleModel.newPersonEntry("jack");
+ final 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", person, optional.get());
- DOMStoreThreePhaseCommitCohort cohort2 = readWriteTx.ready();
+ final DOMStoreThreePhaseCommitCohort cohort2 = readWriteTx.ready();
writeTx = txChain.newWriteOnlyTransaction();
writeTx.delete(carPath);
- DOMStoreThreePhaseCommitCohort cohort3 = writeTx.ready();
+ final DOMStoreThreePhaseCommitCohort cohort3 = writeTx.ready();
- ListenableFuture<Boolean> canCommit1 = cohort1.canCommit();
- ListenableFuture<Boolean> canCommit2 = cohort2.canCommit();
+ final ListenableFuture<Boolean> canCommit1 = cohort1.canCommit();
+ final ListenableFuture<Boolean> canCommit2 = cohort2.canCommit();
doCommit(canCommit1, cohort1);
doCommit(canCommit2, cohort2);
txChain.close();
- DOMStoreReadTransaction readTx = dataStore.newReadOnlyTransaction();
+ final DOMStoreReadTransaction readTx = dataStore.newReadOnlyTransaction();
optional = readTx.read(carPath).get(5, TimeUnit.SECONDS);
assertEquals("isPresent", false, optional.isPresent());
public void testCreateChainedTransactionsInQuickSuccession() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
- try (AbstractDataStore dataStore = setupDistributedDataStore(
- "testCreateChainedTransactionsInQuickSuccession", "cars-1")) {
+ try (final AbstractDataStore dataStore = setupAbstractDataStore(
+ testParameter, "testCreateChainedTransactionsInQuickSuccession", "cars-1")) {
- ConcurrentDOMDataBroker broker = new ConcurrentDOMDataBroker(
+ final ConcurrentDOMDataBroker broker = new ConcurrentDOMDataBroker(
ImmutableMap.<LogicalDatastoreType, DOMStore>builder()
.put(LogicalDatastoreType.CONFIGURATION, dataStore).build(),
MoreExecutors.directExecutor());
- TransactionChainListener listener = Mockito.mock(TransactionChainListener.class);
+ final TransactionChainListener listener = Mockito.mock(TransactionChainListener.class);
DOMTransactionChain txChain = broker.createTransactionChain(listener);
- List<CheckedFuture<Void, TransactionCommitFailedException>> futures = new ArrayList<>();
+ final List<CheckedFuture<Void, TransactionCommitFailedException>> futures = new ArrayList<>();
- DOMDataWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
+ final 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 numCars = 100;
for (int i = 0; i < numCars; i++) {
- DOMDataReadWriteTransaction rwTx = txChain.newReadWriteTransaction();
+ final DOMDataReadWriteTransaction rwTx = txChain.newReadWriteTransaction();
rwTx.merge(LogicalDatastoreType.CONFIGURATION, CarsModel.newCarPath("car" + i),
CarsModel.newCarEntry("car" + i, BigInteger.valueOf(20000)));
futures.add(rwTx.submit());
}
- for (CheckedFuture<Void, TransactionCommitFailedException> f : futures) {
+ for (final CheckedFuture<Void, TransactionCommitFailedException> f : futures) {
f.checkedGet();
}
- Optional<NormalizedNode<?, ?>> optional = txChain.newReadOnlyTransaction()
+ final Optional<NormalizedNode<?, ?>> optional = txChain.newReadOnlyTransaction()
.read(LogicalDatastoreType.CONFIGURATION, CarsModel.CAR_LIST_PATH).get(5, TimeUnit.SECONDS);
assertEquals("isPresent", true, optional.isPresent());
assertEquals("# cars", numCars, ((Collection<?>) optional.get().getValue()).size());
public void testCreateChainedTransactionAfterEmptyTxReadied() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
- try (AbstractDataStore dataStore = setupDistributedDataStore(
- "testCreateChainedTransactionAfterEmptyTxReadied", "test-1")) {
+ try (final AbstractDataStore dataStore = setupAbstractDataStore(
+ testParameter, "testCreateChainedTransactionAfterEmptyTxReadied", "test-1")) {
- DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
+ final DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
- DOMStoreReadWriteTransaction rwTx1 = txChain.newReadWriteTransaction();
+ final DOMStoreReadWriteTransaction rwTx1 = txChain.newReadWriteTransaction();
rwTx1.ready();
- DOMStoreReadWriteTransaction rwTx2 = txChain.newReadWriteTransaction();
+ final DOMStoreReadWriteTransaction rwTx2 = txChain.newReadWriteTransaction();
- Optional<NormalizedNode<?, ?>> optional = rwTx2.read(TestModel.TEST_PATH).get(5, TimeUnit.SECONDS);
+ final Optional<NormalizedNode<?, ?>> optional = rwTx2.read(TestModel.TEST_PATH).get(
+ 5, TimeUnit.SECONDS);
assertEquals("isPresent", false, optional.isPresent());
txChain.close();
public void testCreateChainedTransactionWhenPreviousNotReady() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
- try (AbstractDataStore dataStore = setupDistributedDataStore(
- "testCreateChainedTransactionWhenPreviousNotReady", "test-1")) {
+ try (final AbstractDataStore dataStore = setupAbstractDataStore(
+ testParameter, "testCreateChainedTransactionWhenPreviousNotReady", "test-1")) {
final DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
- DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
+ final DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
assertNotNull("newWriteOnlyTransaction returned null", writeTx);
writeTx.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
// Try to create another Tx of each type - each should fail
// b/c the previous Tx wasn't
// readied.
-
assertExceptionOnTxChainCreates(txChain, IllegalStateException.class);
}
}
@Test
public void testCreateChainedTransactionAfterClose() throws Exception {
+ //TODO remove when test passes also for ClientBackedDataStore
+ Assume.assumeTrue(testParameter.equals(DistributedDataStore.class));
+
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
- try (AbstractDataStore dataStore = setupDistributedDataStore(
- "testCreateChainedTransactionAfterClose", "test-1")) {
-
- DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
+ try (AbstractDataStore dataStore = setupAbstractDataStore(
+ testParameter, "testCreateChainedTransactionAfterClose", "test-1")) {
+ final DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
txChain.close();
// Try to create another Tx of each type - should fail b/c
// the previous Tx was closed.
-
assertExceptionOnTxChainCreates(txChain, TransactionChainClosedException.class);
}
}
@Test
public void testChainWithReadOnlyTxAfterPreviousReady() throws Exception {
+ //TODO remove when test passes also for ClientBackedDataStore
+ Assume.assumeTrue(testParameter.equals(DistributedDataStore.class));
+
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
- try (AbstractDataStore dataStore = setupDistributedDataStore(
- "testChainWithReadOnlyTxAfterPreviousReady", "test-1")) {
+ try (final AbstractDataStore dataStore = setupAbstractDataStore(
+ testParameter, "testChainWithReadOnlyTxAfterPreviousReady", "test-1")) {
final DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
// Create a write tx and submit.
-
- DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
+ final DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
writeTx.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
final DOMStoreThreePhaseCommitCohort cohort1 = writeTx.ready();
// Create read-only tx's and issue a read.
-
CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> readFuture1 = txChain
.newReadOnlyTransaction().read(TestModel.TEST_PATH);
.newReadOnlyTransaction().read(TestModel.TEST_PATH);
// Create another write tx and issue the write.
-
DOMStoreWriteTransaction writeTx2 = txChain.newWriteOnlyTransaction();
writeTx2.write(TestModel.OUTER_LIST_PATH,
ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
assertEquals("isPresent", true, readFuture2.checkedGet(5, TimeUnit.SECONDS).isPresent());
// Ensure the writes succeed.
-
DOMStoreThreePhaseCommitCohort cohort2 = writeTx2.ready();
doCommit(cohort1);
@Test
public void testChainedTransactionFailureWithSingleShard() throws Exception {
+ //TODO remove when test passes also for ClientBackedDataStore
+ Assume.assumeTrue(testParameter.equals(DistributedDataStore.class));
+
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
- try (AbstractDataStore dataStore = setupDistributedDataStore(
- "testChainedTransactionFailureWithSingleShard", "cars-1")) {
+ try (final AbstractDataStore dataStore = setupAbstractDataStore(
+ testParameter, "testChainedTransactionFailureWithSingleShard", "cars-1")) {
- ConcurrentDOMDataBroker broker = new ConcurrentDOMDataBroker(
+ final ConcurrentDOMDataBroker broker = new ConcurrentDOMDataBroker(
ImmutableMap.<LogicalDatastoreType, DOMStore>builder()
.put(LogicalDatastoreType.CONFIGURATION, dataStore).build(),
MoreExecutors.directExecutor());
- TransactionChainListener listener = Mockito.mock(TransactionChainListener.class);
- DOMTransactionChain txChain = broker.createTransactionChain(listener);
+ final TransactionChainListener listener = Mockito.mock(TransactionChainListener.class);
+ final DOMTransactionChain txChain = broker.createTransactionChain(listener);
- DOMDataReadWriteTransaction rwTx = txChain.newReadWriteTransaction();
+ final DOMDataReadWriteTransaction writeTx = txChain.newReadWriteTransaction();
+
+ writeTx.put(LogicalDatastoreType.CONFIGURATION, PeopleModel.BASE_PATH,
+ PeopleModel.emptyContainer());
- ContainerNode invalidData = ImmutableContainerNodeBuilder.create()
+ final ContainerNode invalidData = ImmutableContainerNodeBuilder.create()
.withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(CarsModel.BASE_QNAME))
.withChild(ImmutableNodes.leafNode(TestModel.JUNK_QNAME, "junk")).build();
- rwTx.merge(LogicalDatastoreType.CONFIGURATION, CarsModel.BASE_PATH, invalidData);
+ writeTx.merge(LogicalDatastoreType.CONFIGURATION, CarsModel.BASE_PATH, invalidData);
try {
- rwTx.submit().checkedGet(5, TimeUnit.SECONDS);
+ writeTx.submit().checkedGet(5, TimeUnit.SECONDS);
fail("Expected TransactionCommitFailedException");
- } catch (TransactionCommitFailedException e) {
+ } catch (final TransactionCommitFailedException e) {
// Expected
}
- verify(listener, timeout(5000)).onTransactionChainFailed(eq(txChain), eq(rwTx),
+ verify(listener, timeout(5000)).onTransactionChainFailed(eq(txChain), eq(writeTx),
any(Throwable.class));
txChain.close();
@Test
public void testChainedTransactionFailureWithMultipleShards() throws Exception {
+ //TODO remove when test passes also for ClientBackedDataStore
+ Assume.assumeTrue(testParameter.equals(DistributedDataStore.class));
+
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
- try (AbstractDataStore dataStore = setupDistributedDataStore(
- "testChainedTransactionFailureWithMultipleShards", "cars-1", "people-1")) {
+ try (final AbstractDataStore dataStore = setupAbstractDataStore(
+ testParameter, "testChainedTransactionFailureWithMultipleShards", "cars-1", "people-1")) {
- ConcurrentDOMDataBroker broker = new ConcurrentDOMDataBroker(
+ final ConcurrentDOMDataBroker broker = new ConcurrentDOMDataBroker(
ImmutableMap.<LogicalDatastoreType, DOMStore>builder()
.put(LogicalDatastoreType.CONFIGURATION, dataStore).build(),
MoreExecutors.directExecutor());
- TransactionChainListener listener = Mockito.mock(TransactionChainListener.class);
- DOMTransactionChain txChain = broker.createTransactionChain(listener);
+ final TransactionChainListener listener = Mockito.mock(TransactionChainListener.class);
+ final DOMTransactionChain txChain = broker.createTransactionChain(listener);
- DOMDataWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
+ final DOMDataReadWriteTransaction writeTx = txChain.newReadWriteTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, PeopleModel.BASE_PATH,
PeopleModel.emptyContainer());
- ContainerNode invalidData = ImmutableContainerNodeBuilder.create()
+ final ContainerNode invalidData = ImmutableContainerNodeBuilder.create()
.withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(CarsModel.BASE_QNAME))
.withChild(ImmutableNodes.leafNode(TestModel.JUNK_QNAME, "junk")).build();
+ 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) {
+ } catch (final TransactionCommitFailedException e) {
// Expected
}
@Test
public void testChangeListenerRegistration() throws Exception {
+ //TODO remove when test passes also for ClientBackedDataStore
+ Assume.assumeTrue(testParameter.equals(DistributedDataStore.class));
+
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
- try (AbstractDataStore dataStore = setupDistributedDataStore("testChangeListenerRegistration",
- "test-1")) {
+ try (final AbstractDataStore dataStore = setupAbstractDataStore(
+ testParameter, "testChangeListenerRegistration", "test-1")) {
testWriteTransaction(dataStore, TestModel.TEST_PATH,
ImmutableNodes.containerNode(TestModel.TEST_QNAME));
- MockDataChangeListener listener = new MockDataChangeListener(1);
+ final MockDataChangeListener listener = new MockDataChangeListener(1);
- ListenerRegistration<MockDataChangeListener> listenerReg = dataStore
+ final ListenerRegistration<MockDataChangeListener> listenerReg = dataStore
.registerChangeListener(TestModel.TEST_PATH, listener, DataChangeScope.SUBTREE);
assertNotNull("registerChangeListener returned null", listenerReg);
// Wait for the initial notification
-
listener.waitForChangeEvents(TestModel.TEST_PATH);
-
listener.reset(2);
// Write 2 updates.
-
testWriteTransaction(dataStore, TestModel.OUTER_LIST_PATH,
ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1));
// Wait for the 2 updates.
-
listener.waitForChangeEvents(TestModel.OUTER_LIST_PATH, listPath);
-
listenerReg.close();
testWriteTransaction(dataStore,
{
final String name = "transactionIntegrationTest";
- ContainerNode carsNode = CarsModel.newCarsNode(
+ final ContainerNode carsNode = CarsModel.newCarsNode(
CarsModel.newCarsMapNode(CarsModel.newCarEntry("optima", BigInteger.valueOf(20000L)),
CarsModel.newCarEntry("sportage", BigInteger.valueOf(30000L))));
final Snapshot carsSnapshot = Snapshot.create(
new ShardSnapshotState(new MetadataShardDataTreeSnapshot(root)),
- Collections.<ReplicatedLogEntry>emptyList(), 2, 1, 2, 1, 1, "member-1", null);
+ Collections.emptyList(), 2, 1, 2, 1, 1, "member-1", null);
- NormalizedNode<?, ?> peopleNode = PeopleModel.create();
dataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL);
dataTree.setSchemaContext(SchemaContextHelper.full());
+
+ final NormalizedNode<?, ?> peopleNode = PeopleModel.create();
AbstractShardTest.writeToStore(dataTree, PeopleModel.BASE_PATH, peopleNode);
+
root = AbstractShardTest.readStore(dataTree, YangInstanceIdentifier.EMPTY);
- Snapshot peopleSnapshot = Snapshot.create(
+ final Snapshot peopleSnapshot = Snapshot.create(
new ShardSnapshotState(new MetadataShardDataTreeSnapshot(root)),
- Collections.<ReplicatedLogEntry>emptyList(), 2, 1, 2, 1, 1, "member-1", null);
+ Collections.emptyList(), 2, 1, 2, 1, 1, "member-1", null);
restoreFromSnapshot = new DatastoreSnapshot(name, null, Arrays.asList(
new DatastoreSnapshot.ShardSnapshot("cars", carsSnapshot),
new DatastoreSnapshot.ShardSnapshot("people", peopleSnapshot)));
- try (AbstractDataStore dataStore = setupDistributedDataStore(name, "module-shards-member1.conf",
- true, "cars", "people")) {
+ try (final AbstractDataStore dataStore = setupAbstractDataStore(
+ testParameter, name, "module-shards-member1.conf", true, "cars", "people")) {
- DOMStoreReadTransaction readTx = dataStore.newReadOnlyTransaction();
+ final DOMStoreReadTransaction readTx = dataStore.newReadOnlyTransaction();
+ // two reads
Optional<NormalizedNode<?, ?>> optional = readTx.read(CarsModel.BASE_PATH).get(5, TimeUnit.SECONDS);
assertEquals("isPresent", true, optional.isPresent());
assertEquals("Data node", carsNode, optional.get());
{
final String name = "testRecoveryFromPreCarbonSnapshot";
- ContainerNode carsNode = CarsModel.newCarsNode(
+ final ContainerNode carsNode = CarsModel.newCarsNode(
CarsModel.newCarsMapNode(CarsModel.newCarEntry("optima", BigInteger.valueOf(20000L)),
CarsModel.newCarEntry("sportage", BigInteger.valueOf(30000L))));
}
final org.opendaylight.controller.cluster.raft.Snapshot snapshot =
- org.opendaylight.controller.cluster.raft.Snapshot.create(bos.toByteArray(),
- Collections.<ReplicatedLogEntry>emptyList(), 2, 1, 2, 1, 1, "member-1", null);
+ org.opendaylight.controller.cluster.raft.Snapshot.create(bos.toByteArray(),
+ Collections.emptyList(), 2, 1, 2, 1, 1, "member-1", null);
InMemorySnapshotStore.addSnapshot("member-1-shard-cars-" + name, snapshot);
- try (AbstractDataStore dataStore = setupDistributedDataStore(name, "module-shards-member1.conf",
- true, "cars")) {
+ try (AbstractDataStore dataStore = setupAbstractDataStore(
+ testParameter, name, "module-shards-member1.conf", true, "cars")) {
DOMStoreReadTransaction readTx = dataStore.newReadOnlyTransaction();
import com.typesafe.config.ConfigFactory;
import java.math.BigInteger;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import org.junit.After;
+import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameter;
+import org.junit.runners.Parameterized.Parameters;
import org.mockito.Mockito;
import org.mockito.stubbing.Answer;
import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
+import org.opendaylight.controller.cluster.databroker.ClientBackedDataStore;
import org.opendaylight.controller.cluster.databroker.ConcurrentDOMDataBroker;
import org.opendaylight.controller.cluster.datastore.DatastoreContext.Builder;
import org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException;
*
* @author Thomas Pantelis
*/
+@RunWith(Parameterized.class)
public class DistributedDataStoreRemotingIntegrationTest extends AbstractTest {
+ @Parameters(name = "{0}")
+ public static Collection<Object[]> data() {
+ return Arrays.asList(new Object[][] {
+ { DistributedDataStore.class }, { ClientBackedDataStore.class }
+ });
+ }
+
+ @Parameter
+ public Class<? extends AbstractDataStore> testParameter;
+
private static final String[] CARS_AND_PEOPLE = {"cars", "people"};
private static final String[] CARS = {"cars"};
InMemorySnapshotStore.clear();
}
- private void initDatastoresWithCars(final String type) {
+ private void initDatastoresWithCars(final String type) throws Exception {
initDatastores(type, MODULE_SHARDS_CARS_ONLY_1_2, CARS);
}
- private void initDatastoresWithCarsAndPeople(final String type) {
+ private void initDatastoresWithCarsAndPeople(final String type) throws Exception {
initDatastores(type, MODULE_SHARDS_CARS_PEOPLE_1_2, CARS_AND_PEOPLE);
}
- private void initDatastores(final String type, final String moduleShardsConfig, final String[] shards) {
+ private void initDatastores(final String type, final String moduleShardsConfig, final String[] shards)
+ throws Exception {
leaderTestKit = new IntegrationTestKit(leaderSystem, leaderDatastoreContextBuilder);
- leaderDistributedDataStore = leaderTestKit.setupDistributedDataStore(type, moduleShardsConfig, false, shards);
+ leaderDistributedDataStore = leaderTestKit.setupAbstractDataStore(
+ testParameter, type, moduleShardsConfig, false, shards);
followerTestKit = new IntegrationTestKit(followerSystem, followerDatastoreContextBuilder);
- followerDistributedDataStore = followerTestKit.setupDistributedDataStore(type, moduleShardsConfig, false,
- shards);
+ followerDistributedDataStore = followerTestKit.setupAbstractDataStore(
+ testParameter, type, moduleShardsConfig, false, shards);
leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorContext(), shards);
}
private static void verifyCars(final DOMStoreReadTransaction readTx, final MapEntryNode... entries)
throws Exception {
- Optional<NormalizedNode<?, ?>> optional = readTx.read(CarsModel.CAR_LIST_PATH).get(5, TimeUnit.SECONDS);
+ final Optional<NormalizedNode<?, ?>> optional = readTx.read(CarsModel.CAR_LIST_PATH).get(5, TimeUnit.SECONDS);
assertEquals("isPresent", true, optional.isPresent());
- CollectionNodeBuilder<MapEntryNode, MapNode> listBuilder = ImmutableNodes.mapNodeBuilder(CarsModel.CAR_QNAME);
- for (NormalizedNode<?, ?> entry: entries) {
+ final CollectionNodeBuilder<MapEntryNode, MapNode> listBuilder = ImmutableNodes.mapNodeBuilder(
+ CarsModel.CAR_QNAME);
+ for (final NormalizedNode<?, ?> entry: entries) {
listBuilder.withChild((MapEntryNode) entry);
}
private static void verifyNode(final DOMStoreReadTransaction readTx, final YangInstanceIdentifier path,
final NormalizedNode<?, ?> expNode) throws Exception {
- Optional<NormalizedNode<?, ?>> optional = readTx.read(path).get(5, TimeUnit.SECONDS);
+ final Optional<NormalizedNode<?, ?>> optional = readTx.read(path).get(5, TimeUnit.SECONDS);
assertEquals("isPresent", true, optional.isPresent());
assertEquals("Data node", expNode, optional.get());
}
private static void verifyExists(final DOMStoreReadTransaction readTx, final YangInstanceIdentifier path)
throws Exception {
- Boolean exists = readTx.exists(path).get(5, TimeUnit.SECONDS);
+ final Boolean exists = readTx.exists(path).get(5, TimeUnit.SECONDS);
assertEquals("exists", true, exists);
}
@Test
public void testWriteTransactionWithSingleShard() throws Exception {
- String testName = "testWriteTransactionWithSingleShard";
+ final String testName = "testWriteTransactionWithSingleShard";
initDatastoresWithCars(testName);
- String followerCarShardName = "member-2-shard-cars-" + testName;
+ final String followerCarShardName = "member-2-shard-cars-" + testName;
InMemoryJournal.addWriteMessagesCompleteLatch(followerCarShardName, 2, ApplyJournalEntries.class);
DOMStoreWriteTransaction writeTx = followerDistributedDataStore.newWriteOnlyTransaction();
writeTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
writeTx.write(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
- MapEntryNode car1 = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
- YangInstanceIdentifier car1Path = CarsModel.newCarPath("optima");
+ final MapEntryNode car1 = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
+ final YangInstanceIdentifier car1Path = CarsModel.newCarPath("optima");
writeTx.merge(car1Path, car1);
- MapEntryNode car2 = CarsModel.newCarEntry("sportage", BigInteger.valueOf(25000));
- YangInstanceIdentifier car2Path = CarsModel.newCarPath("sportage");
+ final MapEntryNode car2 = CarsModel.newCarEntry("sportage", BigInteger.valueOf(25000));
+ final YangInstanceIdentifier car2Path = CarsModel.newCarPath("sportage");
writeTx.merge(car2Path, car2);
followerTestKit.doCommit(writeTx.ready());
JavaTestKit.shutdownActorSystem(leaderSystem, null, true);
JavaTestKit.shutdownActorSystem(followerSystem, null, true);
- ActorSystem newSystem = ActorSystem.create("reinstated-member2", ConfigFactory.load().getConfig("Member2"));
+ final ActorSystem newSystem = ActorSystem.create("reinstated-member2", ConfigFactory.load()
+ .getConfig("Member2"));
- try (AbstractDataStore member2Datastore = new IntegrationTestKit(newSystem, leaderDatastoreContextBuilder)
- .setupDistributedDataStore(testName, "module-shards-member2", true, CARS_AND_PEOPLE)) {
+ try (final AbstractDataStore member2Datastore = new IntegrationTestKit(newSystem, leaderDatastoreContextBuilder)
+ .setupAbstractDataStore(testParameter, testName, "module-shards-member2", true, CARS_AND_PEOPLE)) {
verifyCars(member2Datastore.newReadOnlyTransaction(), car2);
}
public void testReadWriteTransactionWithSingleShard() throws Exception {
initDatastoresWithCars("testReadWriteTransactionWithSingleShard");
- DOMStoreReadWriteTransaction rwTx = followerDistributedDataStore.newReadWriteTransaction();
+ final DOMStoreReadWriteTransaction rwTx = followerDistributedDataStore.newReadWriteTransaction();
assertNotNull("newReadWriteTransaction returned null", rwTx);
rwTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
rwTx.write(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
- MapEntryNode car1 = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
+ final MapEntryNode car1 = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
rwTx.merge(CarsModel.newCarPath("optima"), car1);
verifyCars(rwTx, car1);
- MapEntryNode car2 = CarsModel.newCarEntry("sportage", BigInteger.valueOf(25000));
- YangInstanceIdentifier car2Path = CarsModel.newCarPath("sportage");
+ final MapEntryNode car2 = CarsModel.newCarEntry("sportage", BigInteger.valueOf(25000));
+ final YangInstanceIdentifier car2Path = CarsModel.newCarPath("sportage");
rwTx.merge(car2Path, car2);
verifyExists(rwTx, car2Path);
public void testWriteTransactionWithMultipleShards() throws Exception {
initDatastoresWithCarsAndPeople("testWriteTransactionWithMultipleShards");
- DOMStoreWriteTransaction writeTx = followerDistributedDataStore.newWriteOnlyTransaction();
+ final DOMStoreWriteTransaction writeTx = followerDistributedDataStore.newWriteOnlyTransaction();
assertNotNull("newWriteOnlyTransaction returned null", writeTx);
- YangInstanceIdentifier carsPath = CarsModel.BASE_PATH;
- NormalizedNode<?, ?> carsNode = CarsModel.emptyContainer();
+ final YangInstanceIdentifier carsPath = CarsModel.BASE_PATH;
+ final NormalizedNode<?, ?> carsNode = CarsModel.emptyContainer();
writeTx.write(carsPath, carsNode);
- YangInstanceIdentifier peoplePath = PeopleModel.BASE_PATH;
- NormalizedNode<?, ?> peopleNode = PeopleModel.emptyContainer();
+ final YangInstanceIdentifier peoplePath = PeopleModel.BASE_PATH;
+ final NormalizedNode<?, ?> peopleNode = PeopleModel.emptyContainer();
writeTx.write(peoplePath, peopleNode);
followerTestKit.doCommit(writeTx.ready());
- DOMStoreReadTransaction readTx = followerDistributedDataStore.newReadOnlyTransaction();
+ final DOMStoreReadTransaction readTx = followerDistributedDataStore.newReadOnlyTransaction();
verifyNode(readTx, carsPath, carsNode);
verifyNode(readTx, peoplePath, peopleNode);
public void testReadWriteTransactionWithMultipleShards() throws Exception {
initDatastoresWithCarsAndPeople("testReadWriteTransactionWithMultipleShards");
- DOMStoreReadWriteTransaction rwTx = followerDistributedDataStore.newReadWriteTransaction();
+ final DOMStoreReadWriteTransaction rwTx = followerDistributedDataStore.newReadWriteTransaction();
assertNotNull("newReadWriteTransaction returned null", rwTx);
- YangInstanceIdentifier carsPath = CarsModel.BASE_PATH;
- NormalizedNode<?, ?> carsNode = CarsModel.emptyContainer();
+ final YangInstanceIdentifier carsPath = CarsModel.BASE_PATH;
+ final NormalizedNode<?, ?> carsNode = CarsModel.emptyContainer();
rwTx.write(carsPath, carsNode);
- YangInstanceIdentifier peoplePath = PeopleModel.BASE_PATH;
- NormalizedNode<?, ?> peopleNode = PeopleModel.emptyContainer();
+ final YangInstanceIdentifier peoplePath = PeopleModel.BASE_PATH;
+ final NormalizedNode<?, ?> peopleNode = PeopleModel.emptyContainer();
rwTx.write(peoplePath, peopleNode);
followerTestKit.doCommit(rwTx.ready());
- DOMStoreReadTransaction readTx = followerDistributedDataStore.newReadOnlyTransaction();
+ final DOMStoreReadTransaction readTx = followerDistributedDataStore.newReadOnlyTransaction();
verifyNode(readTx, carsPath, carsNode);
verifyNode(readTx, peoplePath, peopleNode);
public void testTransactionChainWithSingleShard() throws Exception {
initDatastoresWithCars("testTransactionChainWithSingleShard");
- DOMStoreTransactionChain txChain = followerDistributedDataStore.createTransactionChain();
+ final DOMStoreTransactionChain txChain = followerDistributedDataStore.createTransactionChain();
// Add the top-level cars container with write-only.
- DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
+ final DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
assertNotNull("newWriteOnlyTransaction returned null", writeTx);
writeTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
- writeTx.ready();
+ final DOMStoreThreePhaseCommitCohort writeTxReady = writeTx.ready();
// Verify the top-level cars container with read-only.
// Perform car operations with read-write.
- DOMStoreReadWriteTransaction rwTx = txChain.newReadWriteTransaction();
+ final DOMStoreReadWriteTransaction rwTx = txChain.newReadWriteTransaction();
verifyNode(rwTx, CarsModel.BASE_PATH, CarsModel.emptyContainer());
rwTx.merge(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
- MapEntryNode car1 = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
- YangInstanceIdentifier car1Path = CarsModel.newCarPath("optima");
+ final MapEntryNode car1 = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
+ final YangInstanceIdentifier car1Path = CarsModel.newCarPath("optima");
rwTx.write(car1Path, car1);
verifyExists(rwTx, car1Path);
verifyCars(rwTx, car1);
- MapEntryNode car2 = CarsModel.newCarEntry("sportage", BigInteger.valueOf(25000));
+ final MapEntryNode car2 = CarsModel.newCarEntry("sportage", BigInteger.valueOf(25000));
rwTx.merge(CarsModel.newCarPath("sportage"), car2);
rwTx.delete(car1Path);
+ followerTestKit.doCommit(writeTxReady);
+
followerTestKit.doCommit(rwTx.ready());
txChain.close();
public void testTransactionChainWithMultipleShards() throws Exception {
initDatastoresWithCarsAndPeople("testTransactionChainWithMultipleShards");
- DOMStoreTransactionChain txChain = followerDistributedDataStore.createTransactionChain();
+ final DOMStoreTransactionChain txChain = followerDistributedDataStore.createTransactionChain();
DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
assertNotNull("newWriteOnlyTransaction returned null", writeTx);
followerTestKit.doCommit(writeTx.ready());
- DOMStoreReadWriteTransaction readWriteTx = txChain.newReadWriteTransaction();
+ final DOMStoreReadWriteTransaction readWriteTx = txChain.newReadWriteTransaction();
- MapEntryNode car = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
- YangInstanceIdentifier carPath = CarsModel.newCarPath("optima");
+ final MapEntryNode car = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
+ final YangInstanceIdentifier carPath = CarsModel.newCarPath("optima");
readWriteTx.write(carPath, car);
- MapEntryNode person = PeopleModel.newPersonEntry("jack");
- YangInstanceIdentifier personPath = PeopleModel.newPersonPath("jack");
+ final MapEntryNode person = PeopleModel.newPersonEntry("jack");
+ final 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", person, optional.get());
- DOMStoreThreePhaseCommitCohort cohort2 = readWriteTx.ready();
+ final DOMStoreThreePhaseCommitCohort cohort2 = readWriteTx.ready();
writeTx = txChain.newWriteOnlyTransaction();
writeTx.delete(personPath);
- DOMStoreThreePhaseCommitCohort cohort3 = writeTx.ready();
+ final DOMStoreThreePhaseCommitCohort cohort3 = writeTx.ready();
followerTestKit.doCommit(cohort2);
followerTestKit.doCommit(cohort3);
txChain.close();
- DOMStoreReadTransaction readTx = followerDistributedDataStore.newReadOnlyTransaction();
+ final DOMStoreReadTransaction readTx = followerDistributedDataStore.newReadOnlyTransaction();
verifyCars(readTx, car);
optional = readTx.read(personPath).get(5, TimeUnit.SECONDS);
public void testChainedTransactionFailureWithSingleShard() throws Exception {
initDatastoresWithCars("testChainedTransactionFailureWithSingleShard");
- ConcurrentDOMDataBroker broker = new ConcurrentDOMDataBroker(
+ final ConcurrentDOMDataBroker broker = new ConcurrentDOMDataBroker(
ImmutableMap.<LogicalDatastoreType, DOMStore>builder().put(
LogicalDatastoreType.CONFIGURATION, followerDistributedDataStore).build(),
MoreExecutors.directExecutor());
- TransactionChainListener listener = Mockito.mock(TransactionChainListener.class);
- DOMTransactionChain txChain = broker.createTransactionChain(listener);
+ final TransactionChainListener listener = Mockito.mock(TransactionChainListener.class);
+ final DOMTransactionChain txChain = broker.createTransactionChain(listener);
- DOMDataWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
+ final DOMDataWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
- ContainerNode invalidData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(
+ final ContainerNode invalidData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(
new YangInstanceIdentifier.NodeIdentifier(CarsModel.BASE_QNAME))
.withChild(ImmutableNodes.leafNode(TestModel.JUNK_QNAME, "junk")).build();
try {
writeTx.submit().checkedGet(5, TimeUnit.SECONDS);
fail("Expected TransactionCommitFailedException");
- } catch (TransactionCommitFailedException e) {
+ } catch (final TransactionCommitFailedException e) {
// Expected
}
public void testChainedTransactionFailureWithMultipleShards() throws Exception {
initDatastoresWithCarsAndPeople("testChainedTransactionFailureWithMultipleShards");
- ConcurrentDOMDataBroker broker = new ConcurrentDOMDataBroker(
+ final ConcurrentDOMDataBroker broker = new ConcurrentDOMDataBroker(
ImmutableMap.<LogicalDatastoreType, DOMStore>builder().put(
LogicalDatastoreType.CONFIGURATION, followerDistributedDataStore).build(),
MoreExecutors.directExecutor());
- TransactionChainListener listener = Mockito.mock(TransactionChainListener.class);
- DOMTransactionChain txChain = broker.createTransactionChain(listener);
+ final TransactionChainListener listener = Mockito.mock(TransactionChainListener.class);
+ final DOMTransactionChain txChain = broker.createTransactionChain(listener);
- DOMDataWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
+ final DOMDataWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, PeopleModel.BASE_PATH, PeopleModel.emptyContainer());
- ContainerNode invalidData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(
+ final ContainerNode invalidData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(
new YangInstanceIdentifier.NodeIdentifier(CarsModel.BASE_QNAME))
.withChild(ImmutableNodes.leafNode(TestModel.JUNK_QNAME, "junk")).build();
try {
writeTx.submit().checkedGet(5, TimeUnit.SECONDS);
fail("Expected TransactionCommitFailedException");
- } catch (TransactionCommitFailedException e) {
+ } catch (final TransactionCommitFailedException e) {
// Expected
}
@Test
public void testSingleShardTransactionsWithLeaderChanges() throws Exception {
- String testName = "testSingleShardTransactionsWithLeaderChanges";
+ //TODO remove when test passes also for ClientBackedDataStore
+ Assume.assumeTrue(testParameter.equals(DistributedDataStore.class));
+ final String testName = "testSingleShardTransactionsWithLeaderChanges";
initDatastoresWithCars(testName);
- String followerCarShardName = "member-2-shard-cars-" + testName;
+ final String followerCarShardName = "member-2-shard-cars-" + testName;
InMemoryJournal.addWriteMessagesCompleteLatch(followerCarShardName, 1, ApplyJournalEntries.class);
// Write top-level car container from the follower so it uses a remote Tx.
leaderSystem = ActorSystem.create("cluster-test", ConfigFactory.load().getConfig("Member1"));
Cluster.get(leaderSystem).join(MEMBER_2_ADDRESS);
- DatastoreContext.Builder newMember1Builder = DatastoreContext.newBuilder()
+ final DatastoreContext.Builder newMember1Builder = DatastoreContext.newBuilder()
.shardHeartbeatIntervalInMillis(100).shardElectionTimeoutFactor(5);
IntegrationTestKit newMember1TestKit = new IntegrationTestKit(leaderSystem, newMember1Builder);
- try (AbstractDataStore ds =
- newMember1TestKit.setupDistributedDataStore(testName, MODULE_SHARDS_CARS_ONLY_1_2, false, CARS)) {
+ try (final AbstractDataStore ds =
+ newMember1TestKit.setupAbstractDataStore(
+ testParameter, testName, MODULE_SHARDS_CARS_ONLY_1_2, false, CARS)) {
followerTestKit.waitUntilLeader(followerDistributedDataStore.getActorContext(), CARS);
initDatastoresWithCars("testReadyLocalTransactionForwardedToLeader");
followerTestKit.waitUntilLeader(followerDistributedDataStore.getActorContext(), "cars");
- Optional<ActorRef> carsFollowerShard = followerDistributedDataStore.getActorContext().findLocalShard("cars");
+ final Optional<ActorRef> carsFollowerShard = followerDistributedDataStore.getActorContext()
+ .findLocalShard("cars");
assertEquals("Cars follower shard found", true, carsFollowerShard.isPresent());
- TipProducingDataTree dataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL);
+ final TipProducingDataTree dataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL);
dataTree.setSchemaContext(SchemaContextHelper.full());
// Send a tx with immediate commit.
new WriteModification(CarsModel.BASE_PATH, CarsModel.emptyContainer()).apply(modification);
new MergeModification(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode()).apply(modification);
- MapEntryNode car1 = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
+ final MapEntryNode car1 = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
new WriteModification(CarsModel.newCarPath("optima"), car1).apply(modification);
modification.ready();
assertEquals("Response type", ReadyTransactionReply.class, resp.getClass());
- ActorSelection txActor = leaderDistributedDataStore.getActorContext().actorSelection(
+ final ActorSelection txActor = leaderDistributedDataStore.getActorContext().actorSelection(
((ReadyTransactionReply)resp).getCohortPath());
- Supplier<Short> versionSupplier = Mockito.mock(Supplier.class);
+ final Supplier<Short> versionSupplier = Mockito.mock(Supplier.class);
Mockito.doReturn(DataStoreVersions.CURRENT_VERSION).when(versionSupplier).get();
ThreePhaseCommitCohortProxy cohort = new ThreePhaseCommitCohortProxy(
leaderDistributedDataStore.getActorContext(), Arrays.asList(
initDatastoresWithCars("testForwardedReadyTransactionForwardedToLeader");
followerTestKit.waitUntilLeader(followerDistributedDataStore.getActorContext(), "cars");
- Optional<ActorRef> carsFollowerShard = followerDistributedDataStore.getActorContext().findLocalShard("cars");
+ final Optional<ActorRef> carsFollowerShard = followerDistributedDataStore.getActorContext()
+ .findLocalShard("cars");
assertEquals("Cars follower shard found", true, carsFollowerShard.isPresent());
carsFollowerShard.get().tell(GetShardDataTree.INSTANCE, followerTestKit.getRef());
- DataTree dataTree = followerTestKit.expectMsgClass(DataTree.class);
+ final DataTree dataTree = followerTestKit.expectMsgClass(DataTree.class);
// Send a tx with immediate commit.
new WriteModification(CarsModel.BASE_PATH, CarsModel.emptyContainer()).apply(modification);
new MergeModification(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode()).apply(modification);
- MapEntryNode car1 = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
+ final MapEntryNode car1 = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
new WriteModification(CarsModel.newCarPath("optima"), car1).apply(modification);
ForwardedReadyTransaction forwardedReady = new ForwardedReadyTransaction(tx1,
ActorSelection txActor = leaderDistributedDataStore.getActorContext().actorSelection(
((ReadyTransactionReply)resp).getCohortPath());
- Supplier<Short> versionSupplier = Mockito.mock(Supplier.class);
+ final Supplier<Short> versionSupplier = Mockito.mock(Supplier.class);
Mockito.doReturn(DataStoreVersions.CURRENT_VERSION).when(versionSupplier).get();
- ThreePhaseCommitCohortProxy cohort = new ThreePhaseCommitCohortProxy(
+ final ThreePhaseCommitCohortProxy cohort = new ThreePhaseCommitCohortProxy(
leaderDistributedDataStore.getActorContext(), Arrays.asList(
new ThreePhaseCommitCohortProxy.CohortInfo(Futures.successful(txActor), versionSupplier)), tx2);
cohort.canCommit().get(5, TimeUnit.SECONDS);
@Test
public void testTransactionForwardedToLeaderAfterRetry() throws Exception {
+ //TODO remove when test passes also for ClientBackedDataStore
+ Assume.assumeTrue(testParameter.equals(DistributedDataStore.class));
followerDatastoreContextBuilder.shardBatchedModificationCount(2);
leaderDatastoreContextBuilder.shardBatchedModificationCount(2);
initDatastoresWithCarsAndPeople("testTransactionForwardedToLeaderAfterRetry");
// Do an initial write to get the primary shard info cached.
- DOMStoreWriteTransaction initialWriteTx = followerDistributedDataStore.newWriteOnlyTransaction();
+ final DOMStoreWriteTransaction initialWriteTx = followerDistributedDataStore.newWriteOnlyTransaction();
initialWriteTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
initialWriteTx.write(PeopleModel.BASE_PATH, PeopleModel.emptyContainer());
followerTestKit.doCommit(initialWriteTx.ready());
// Prepare, ready and canCommit a WO tx that writes to 2 shards. This will become the current tx in
// the leader shard.
- DOMStoreWriteTransaction writeTx1 = followerDistributedDataStore.newWriteOnlyTransaction();
+ final DOMStoreWriteTransaction writeTx1 = followerDistributedDataStore.newWriteOnlyTransaction();
writeTx1.write(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
writeTx1.write(PeopleModel.BASE_PATH, PeopleModel.emptyContainer());
- DOMStoreThreePhaseCommitCohort writeTx1Cohort = writeTx1.ready();
- ListenableFuture<Boolean> writeTx1CanCommit = writeTx1Cohort.canCommit();
+ final DOMStoreThreePhaseCommitCohort writeTx1Cohort = writeTx1.ready();
+ final ListenableFuture<Boolean> writeTx1CanCommit = writeTx1Cohort.canCommit();
writeTx1CanCommit.get(5, TimeUnit.SECONDS);
// Prepare and ready another WO tx that writes to 2 shards but don't canCommit yet. This will be queued
// in the leader shard.
- DOMStoreWriteTransaction writeTx2 = followerDistributedDataStore.newWriteOnlyTransaction();
- LinkedList<MapEntryNode> cars = new LinkedList<>();
+ final DOMStoreWriteTransaction writeTx2 = followerDistributedDataStore.newWriteOnlyTransaction();
+ final LinkedList<MapEntryNode> cars = new LinkedList<>();
int carIndex = 1;
cars.add(CarsModel.newCarEntry("car" + carIndex, BigInteger.valueOf(carIndex)));
writeTx2.write(CarsModel.newCarPath("car" + carIndex), cars.getLast());
// leader shard (with shardBatchedModificationCount set to 2). The 3rd BatchedModidifications will be
// sent on ready.
- DOMStoreWriteTransaction writeTx3 = followerDistributedDataStore.newWriteOnlyTransaction();
+ final DOMStoreWriteTransaction writeTx3 = followerDistributedDataStore.newWriteOnlyTransaction();
for (int i = 1; i <= 5; i++, carIndex++) {
cars.add(CarsModel.newCarEntry("car" + carIndex, BigInteger.valueOf(carIndex)));
writeTx3.write(CarsModel.newCarPath("car" + carIndex), cars.getLast());
// Prepare another WO that writes to a single shard. This will send a single BatchedModidifications
// message on ready.
- DOMStoreWriteTransaction writeTx4 = followerDistributedDataStore.newWriteOnlyTransaction();
+ final DOMStoreWriteTransaction writeTx4 = followerDistributedDataStore.newWriteOnlyTransaction();
cars.add(CarsModel.newCarEntry("car" + carIndex, BigInteger.valueOf(carIndex)));
writeTx4.write(CarsModel.newCarPath("car" + carIndex), cars.getLast());
carIndex++;
// Prepare a RW tx that will create a tx actor and send a ForwardedReadyTransaciton message to the
// leader shard on ready.
- DOMStoreReadWriteTransaction readWriteTx = followerDistributedDataStore.newReadWriteTransaction();
+ final DOMStoreReadWriteTransaction readWriteTx = followerDistributedDataStore.newReadWriteTransaction();
cars.add(CarsModel.newCarEntry("car" + carIndex, BigInteger.valueOf(carIndex)));
readWriteTx.write(CarsModel.newCarPath("car" + carIndex), cars.getLast());
// Submit all tx's - the messages should get queued for retry.
- ListenableFuture<Boolean> writeTx2CanCommit = writeTx2Cohort.canCommit();
+ final ListenableFuture<Boolean> writeTx2CanCommit = writeTx2Cohort.canCommit();
final DOMStoreThreePhaseCommitCohort writeTx3Cohort = writeTx3.ready();
final DOMStoreThreePhaseCommitCohort writeTx4Cohort = writeTx4.ready();
final DOMStoreThreePhaseCommitCohort rwTxCohort = readWriteTx.ready();
@Test
public void testLeadershipTransferOnShutdown() throws Exception {
+ //TODO remove when test passes also for ClientBackedDataStore
+ Assume.assumeTrue(testParameter.equals(DistributedDataStore.class));
leaderDatastoreContextBuilder.shardBatchedModificationCount(1);
followerDatastoreContextBuilder.shardElectionTimeoutFactor(10).customRaftPolicyImplementation(null);
- String testName = "testLeadershipTransferOnShutdown";
+ final String testName = "testLeadershipTransferOnShutdown";
initDatastores(testName, MODULE_SHARDS_CARS_PEOPLE_1_2_3, CARS_AND_PEOPLE);
- IntegrationTestKit follower2TestKit = new IntegrationTestKit(follower2System,
+ final IntegrationTestKit follower2TestKit = new IntegrationTestKit(follower2System,
DatastoreContext.newBuilderFrom(followerDatastoreContextBuilder.build()).operationTimeoutInMillis(100));
- try (AbstractDataStore follower2DistributedDataStore = follower2TestKit.setupDistributedDataStore(testName,
- MODULE_SHARDS_CARS_PEOPLE_1_2_3, false)) {
+ try (final AbstractDataStore follower2DistributedDataStore = follower2TestKit.setupAbstractDataStore(
+ testParameter, testName, MODULE_SHARDS_CARS_PEOPLE_1_2_3, false)) {
// Create and submit a couple tx's so they're pending.
stats -> assertEquals("getTxCohortCacheSize", 1, stats.getTxCohortCacheSize()));
writeTx = followerDistributedDataStore.newWriteOnlyTransaction();
- MapEntryNode car = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
+ final MapEntryNode car = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
writeTx.write(CarsModel.newCarPath("optima"), car);
final DOMStoreThreePhaseCommitCohort cohort2 = writeTx.ready();
sendDatastoreContextUpdate(leaderDistributedDataStore, leaderDatastoreContextBuilder
.shardElectionTimeoutFactor(100));
- FiniteDuration duration = FiniteDuration.create(5, TimeUnit.SECONDS);
- Future<ActorRef> future = leaderDistributedDataStore.getActorContext().findLocalShardAsync("cars");
- ActorRef leaderActor = Await.result(future, duration);
+ final FiniteDuration duration = FiniteDuration.create(5, TimeUnit.SECONDS);
+ final Future<ActorRef> future = leaderDistributedDataStore.getActorContext().findLocalShardAsync("cars");
+ final ActorRef leaderActor = Await.result(future, duration);
- Future<Boolean> stopFuture = Patterns.gracefulStop(leaderActor, duration, Shutdown.INSTANCE);
+ final Future<Boolean> stopFuture = Patterns.gracefulStop(leaderActor, duration, Shutdown.INSTANCE);
// Commit the 2 transactions. They should finish and succeed.
// Wait for the leader actor stopped.
- Boolean stopped = Await.result(stopFuture, duration);
+ final Boolean stopped = Await.result(stopFuture, duration);
assertEquals("Stopped", Boolean.TRUE, stopped);
// Verify leadership was transferred by reading the committed data from the other nodes.
@Test
public void testTransactionWithIsolatedLeader() throws Exception {
+ //TODO remove when test passes also for ClientBackedDataStore
+ Assume.assumeTrue(testParameter.equals(DistributedDataStore.class));
// Set the isolated leader check interval high so we can control the switch to IsolatedLeader.
leaderDatastoreContextBuilder.shardIsolatedLeaderCheckIntervalInMillis(10000000);
- String testName = "testTransactionWithIsolatedLeader";
+ final String testName = "testTransactionWithIsolatedLeader";
initDatastoresWithCars(testName);
// Tx that is submitted after the follower is stopped but before the leader transitions to IsolatedLeader.
- DOMStoreWriteTransaction preIsolatedLeaderWriteTx = leaderDistributedDataStore.newWriteOnlyTransaction();
+ final DOMStoreWriteTransaction preIsolatedLeaderWriteTx = leaderDistributedDataStore.newWriteOnlyTransaction();
preIsolatedLeaderWriteTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
// Tx that is submitted after the leader transitions to IsolatedLeader.
- DOMStoreWriteTransaction noShardLeaderWriteTx = leaderDistributedDataStore.newWriteOnlyTransaction();
+ final DOMStoreWriteTransaction noShardLeaderWriteTx = leaderDistributedDataStore.newWriteOnlyTransaction();
noShardLeaderWriteTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
// Tx that is submitted after the follower is reinstated.
- DOMStoreWriteTransaction successWriteTx = leaderDistributedDataStore.newWriteOnlyTransaction();
+ final DOMStoreWriteTransaction successWriteTx = leaderDistributedDataStore.newWriteOnlyTransaction();
successWriteTx.merge(CarsModel.BASE_PATH, CarsModel.emptyContainer());
// Stop the follower
try {
leaderTestKit.doCommit(noShardLeaderWriteTx.ready());
fail("Expected NoShardLeaderException");
- } catch (ExecutionException e) {
- assertEquals("getCause", NoShardLeaderException.class, e.getCause().getClass());
+ } catch (final ExecutionException e) {
+ assertEquals("getCause", NoShardLeaderException.class, Throwables.getRootCause(e).getClass());
}
sendDatastoreContextUpdate(leaderDistributedDataStore, leaderDatastoreContextBuilder
.shardElectionTimeoutFactor(100));
- DOMStoreThreePhaseCommitCohort successTxCohort = successWriteTx.ready();
+ final DOMStoreThreePhaseCommitCohort successTxCohort = successWriteTx.ready();
- followerDistributedDataStore = followerTestKit.setupDistributedDataStore(testName,
- MODULE_SHARDS_CARS_ONLY_1_2, false, CARS);
+ followerDistributedDataStore = followerTestKit.setupAbstractDataStore(
+ testParameter, testName, MODULE_SHARDS_CARS_ONLY_1_2, false, CARS);
leaderTestKit.doCommit(preIsolatedLeaderTxCohort);
leaderTestKit.doCommit(successTxCohort);
@Test(expected = AskTimeoutException.class)
public void testTransactionWithShardLeaderNotResponding() throws Exception {
+ //TODO remove when test passes also for ClientBackedDataStore
+ Assume.assumeTrue(testParameter.equals(DistributedDataStore.class));
followerDatastoreContextBuilder.shardElectionTimeoutFactor(50);
initDatastoresWithCars("testTransactionWithShardLeaderNotResponding");
// Do an initial read to get the primary shard info cached.
- DOMStoreReadTransaction readTx = followerDistributedDataStore.newReadOnlyTransaction();
+ final DOMStoreReadTransaction readTx = followerDistributedDataStore.newReadOnlyTransaction();
readTx.read(CarsModel.BASE_PATH).checkedGet(5, TimeUnit.SECONDS);
// Shutdown the leader and try to create a new tx.
followerDatastoreContextBuilder.operationTimeoutInMillis(50).shardElectionTimeoutFactor(1);
sendDatastoreContextUpdate(followerDistributedDataStore, followerDatastoreContextBuilder);
- DOMStoreReadWriteTransaction rwTx = followerDistributedDataStore.newReadWriteTransaction();
+ final DOMStoreReadWriteTransaction rwTx = followerDistributedDataStore.newReadWriteTransaction();
rwTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
try {
followerTestKit.doCommit(rwTx.ready());
- } catch (ExecutionException e) {
+ } catch (final ExecutionException e) {
assertTrue("Expected ShardLeaderNotRespondingException cause. Actual: " + e.getCause(),
e.getCause() instanceof ShardLeaderNotRespondingException);
assertNotNull("Expected a nested cause", e.getCause().getCause());
@Test(expected = NoShardLeaderException.class)
public void testTransactionWithCreateTxFailureDueToNoLeader() throws Exception {
+ //TODO remove when test passes also for ClientBackedDataStore
+ Assume.assumeTrue(testParameter.equals(DistributedDataStore.class));
initDatastoresWithCars("testTransactionWithCreateTxFailureDueToNoLeader");
// Do an initial read to get the primary shard info cached.
- DOMStoreReadTransaction readTx = followerDistributedDataStore.newReadOnlyTransaction();
+ final DOMStoreReadTransaction readTx = followerDistributedDataStore.newReadOnlyTransaction();
readTx.read(CarsModel.BASE_PATH).checkedGet(5, TimeUnit.SECONDS);
// Shutdown the leader and try to create a new tx.
sendDatastoreContextUpdate(followerDistributedDataStore, followerDatastoreContextBuilder
.operationTimeoutInMillis(10).shardElectionTimeoutFactor(1).customRaftPolicyImplementation(null));
- DOMStoreReadWriteTransaction rwTx = followerDistributedDataStore.newReadWriteTransaction();
+ final DOMStoreReadWriteTransaction rwTx = followerDistributedDataStore.newReadWriteTransaction();
rwTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
try {
followerTestKit.doCommit(rwTx.ready());
- } catch (ExecutionException e) {
+ } catch (final ExecutionException e) {
Throwables.propagateIfInstanceOf(e.getCause(), Exception.class);
Throwables.propagate(e.getCause());
}
@Test
public void testTransactionRetryWithInitialAskTimeoutExOnCreateTx() throws Exception {
+ //TODO remove when test passes also for ClientBackedDataStore
+ Assume.assumeTrue(testParameter.equals(DistributedDataStore.class));
String testName = "testTransactionRetryWithInitialAskTimeoutExOnCreateTx";
initDatastores(testName, MODULE_SHARDS_CARS_PEOPLE_1_2_3, CARS);
- DatastoreContext.Builder follower2DatastoreContextBuilder = DatastoreContext.newBuilder()
+ final DatastoreContext.Builder follower2DatastoreContextBuilder = DatastoreContext.newBuilder()
.shardHeartbeatIntervalInMillis(100).shardElectionTimeoutFactor(5);
- IntegrationTestKit follower2TestKit = new IntegrationTestKit(follower2System, follower2DatastoreContextBuilder);
+ final IntegrationTestKit follower2TestKit = new IntegrationTestKit(
+ follower2System, follower2DatastoreContextBuilder);
- try (AbstractDataStore ds =
- follower2TestKit.setupDistributedDataStore(testName, MODULE_SHARDS_CARS_PEOPLE_1_2_3, false, CARS)) {
+ try (final AbstractDataStore ds =
+ follower2TestKit.setupAbstractDataStore(
+ testParameter, testName, MODULE_SHARDS_CARS_PEOPLE_1_2_3, false, CARS)) {
followerTestKit.waitForMembersUp("member-1", "member-3");
follower2TestKit.waitForMembersUp("member-1", "member-2");
// Do an initial read to get the primary shard info cached.
- DOMStoreReadTransaction readTx = followerDistributedDataStore.newReadOnlyTransaction();
+ final DOMStoreReadTransaction readTx = followerDistributedDataStore.newReadOnlyTransaction();
readTx.read(CarsModel.BASE_PATH).checkedGet(5, TimeUnit.SECONDS);
// Shutdown the leader and try to create a new tx.
sendDatastoreContextUpdate(followerDistributedDataStore, followerDatastoreContextBuilder
.operationTimeoutInMillis(500).shardElectionTimeoutFactor(1).customRaftPolicyImplementation(null));
- DOMStoreReadWriteTransaction rwTx = followerDistributedDataStore.newReadWriteTransaction();
+ final DOMStoreReadWriteTransaction rwTx = followerDistributedDataStore.newReadWriteTransaction();
rwTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
TipProducingDataTree tree = InMemoryDataTreeFactory.getInstance().create(TreeType.CONFIGURATION);
tree.setSchemaContext(SchemaContextHelper.full());
- ContainerNode carsNode = CarsModel.newCarsNode(
+ final ContainerNode carsNode = CarsModel.newCarsNode(
CarsModel.newCarsMapNode(CarsModel.newCarEntry("optima", BigInteger.valueOf(20000))));
AbstractShardTest.writeToStore(tree, CarsModel.BASE_PATH, carsNode);
- NormalizedNode<?, ?> snapshotRoot = AbstractShardTest.readStore(tree, YangInstanceIdentifier.EMPTY);
- Snapshot initialSnapshot = Snapshot.create(
+ final NormalizedNode<?, ?> snapshotRoot = AbstractShardTest.readStore(tree, YangInstanceIdentifier.EMPTY);
+ final Snapshot initialSnapshot = Snapshot.create(
new ShardSnapshotState(new MetadataShardDataTreeSnapshot(snapshotRoot)),
Collections.emptyList(), 5, 1, 5, 1, 1, null, null);
InMemorySnapshotStore.addSnapshot(leaderCarShardName, initialSnapshot);
initDatastoresWithCars(testName);
- Optional<NormalizedNode<?, ?>> readOptional = leaderDistributedDataStore.newReadOnlyTransaction().read(
+ final Optional<NormalizedNode<?, ?>> readOptional = leaderDistributedDataStore.newReadOnlyTransaction().read(
CarsModel.BASE_PATH).checkedGet(5, TimeUnit.SECONDS);
assertEquals("isPresent", true, readOptional.isPresent());
assertEquals("Node", carsNode, readOptional.get());
initialSnapshot, snapshotRoot);
}
- private static void verifySnapshot(Snapshot actual, Snapshot expected, NormalizedNode<?, ?> expRoot) {
+ private static void verifySnapshot(final Snapshot actual, final Snapshot expected,
+ final NormalizedNode<?, ?> expRoot) {
assertEquals("Snapshot getLastAppliedTerm", expected.getLastAppliedTerm(), actual.getLastAppliedTerm());
assertEquals("Snapshot getLastAppliedIndex", expected.getLastAppliedIndex(), actual.getLastAppliedIndex());
assertEquals("Snapshot getLastTerm", expected.getLastTerm(), actual.getLastTerm());
private static void sendDatastoreContextUpdate(final AbstractDataStore dataStore, final Builder builder) {
final Builder newBuilder = DatastoreContext.newBuilderFrom(builder.build());
- DatastoreContextFactory mockContextFactory = Mockito.mock(DatastoreContextFactory.class);
- Answer<DatastoreContext> answer = invocation -> newBuilder.build();
+ final DatastoreContextFactory mockContextFactory = Mockito.mock(DatastoreContextFactory.class);
+ final Answer<DatastoreContext> answer = invocation -> newBuilder.build();
Mockito.doAnswer(answer).when(mockContextFactory).getBaseDatastoreContext();
Mockito.doAnswer(answer).when(mockContextFactory).getShardDatastoreContext(Mockito.anyString());
dataStore.onDatastoreContextUpdated(mockContextFactory);
import com.google.common.collect.Sets;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.Uninterruptibles;
+import java.lang.reflect.Constructor;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
return datastoreContextBuilder;
}
- public AbstractDataStore setupDistributedDataStore(final String typeName, final String... shardNames) {
- return setupDistributedDataStore(typeName, "module-shards.conf", true, SchemaContextHelper.full(), shardNames);
+ public DistributedDataStore setupDistributedDataStore(final String typeName, final String moduleShardsConfig,
+ final boolean waitUntilLeader,
+ final SchemaContext schemaContext) throws Exception {
+ return setupDistributedDataStore(typeName, moduleShardsConfig, "modules.conf", waitUntilLeader, schemaContext);
}
- public AbstractDataStore setupDistributedDataStore(final String typeName, final boolean waitUntilLeader,
- final String... shardNames) {
- return setupDistributedDataStore(typeName, "module-shards.conf", waitUntilLeader,
+ public DistributedDataStore setupDistributedDataStore(final String typeName, final String moduleShardsConfig,
+ final String modulesConfig,
+ final boolean waitUntilLeader,
+ final SchemaContext schemaContext,
+ final String... shardNames) throws Exception {
+ return (DistributedDataStore) setupAbstractDataStore(DistributedDataStore.class, typeName, moduleShardsConfig,
+ modulesConfig, waitUntilLeader, schemaContext, shardNames);
+ }
+
+ public AbstractDataStore setupAbstractDataStore(final Class<? extends AbstractDataStore> implementation,
+ final String typeName, final String... shardNames)
+ throws Exception {
+ return setupAbstractDataStore(implementation, typeName, "module-shards.conf", true,
+ SchemaContextHelper.full(), shardNames);
+ }
+
+ public AbstractDataStore setupAbstractDataStore(final Class<? extends AbstractDataStore> implementation,
+ final String typeName, final boolean waitUntilLeader,
+ final String... shardNames) throws Exception {
+ return setupAbstractDataStore(implementation, typeName, "module-shards.conf", waitUntilLeader,
SchemaContextHelper.full(), shardNames);
}
- public AbstractDataStore setupDistributedDataStore(final String typeName, final String moduleShardsConfig,
- final boolean waitUntilLeader, final String... shardNames) {
- return setupDistributedDataStore(typeName, moduleShardsConfig, waitUntilLeader,
+ public AbstractDataStore setupAbstractDataStore(final Class<? extends AbstractDataStore> implementation,
+ final String typeName, final String moduleShardsConfig,
+ final boolean waitUntilLeader, final String... shardNames)
+ throws Exception {
+ return setupAbstractDataStore(implementation, typeName, moduleShardsConfig, waitUntilLeader,
SchemaContextHelper.full(), shardNames);
}
- public AbstractDataStore setupDistributedDataStore(final String typeName, final String moduleShardsConfig,
- final boolean waitUntilLeader, final SchemaContext schemaContext, final String... shardNames) {
- return setupDistributedDataStore(typeName, moduleShardsConfig, "modules.conf", waitUntilLeader,
+ public AbstractDataStore setupAbstractDataStore(final Class<? extends AbstractDataStore> implementation,
+ final String typeName, final String moduleShardsConfig,
+ final boolean waitUntilLeader,
+ final SchemaContext schemaContext,
+ final String... shardNames) throws Exception {
+ return setupAbstractDataStore(implementation, typeName, moduleShardsConfig, "modules.conf", waitUntilLeader,
schemaContext, shardNames);
}
- public AbstractDataStore setupDistributedDataStore(final String typeName, final String moduleShardsConfig,
- final String modulesConfig, final boolean waitUntilLeader,
- final SchemaContext schemaContext, final String... shardNames) {
+ private AbstractDataStore setupAbstractDataStore(final Class<? extends AbstractDataStore> implementation,
+ final String typeName, final String moduleShardsConfig,
+ final String modulesConfig, final boolean waitUntilLeader,
+ final SchemaContext schemaContext, final String... shardNames)
+ throws Exception {
final ClusterWrapper cluster = new ClusterWrapperImpl(getSystem());
final Configuration config = new ConfigurationImpl(moduleShardsConfig, modulesConfig);
datastoreContextBuilder.dataStoreName(typeName);
- DatastoreContext datastoreContext = datastoreContextBuilder.build();
- DatastoreContextFactory mockContextFactory = Mockito.mock(DatastoreContextFactory.class);
+ final DatastoreContext datastoreContext = datastoreContextBuilder.build();
+ final DatastoreContextFactory mockContextFactory = Mockito.mock(DatastoreContextFactory.class);
Mockito.doReturn(datastoreContext).when(mockContextFactory).getBaseDatastoreContext();
Mockito.doReturn(datastoreContext).when(mockContextFactory).getShardDatastoreContext(Mockito.anyString());
- AbstractDataStore dataStore = new DistributedDataStore(getSystem(), cluster, config, mockContextFactory,
- restoreFromSnapshot);
+ final Constructor constructor = implementation.getDeclaredConstructor(
+ ActorSystem.class, ClusterWrapper.class, Configuration.class,
+ DatastoreContextFactory.class, DatastoreSnapshot.class);
+
+ final AbstractDataStore dataStore = (AbstractDataStore) constructor.newInstance(
+ getSystem(), cluster, config, mockContextFactory, restoreFromSnapshot);
dataStore.onGlobalContextUpdated(schemaContext);
return shard;
}
- public static void waitUntilShardIsDown(ActorContext actorContext, String shardName) {
+ public static void waitUntilShardIsDown(final ActorContext actorContext, final String shardName) {
for (int i = 0; i < 20 * 5 ; i++) {
LOG.debug("Waiting for shard down {}", shardName);
Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
return this;
}
- public MemberNode build() {
+ public MemberNode build() throws Exception {
Preconditions.checkNotNull(moduleShardsConfig, "moduleShardsConfig must be specified");
Preconditions.checkNotNull(akkaConfig, "akkaConfig must be specified");
Preconditions.checkNotNull(testName, "testName must be specified");
String memberName = new ClusterWrapperImpl(system).getCurrentMemberName().getName();
node.kit.getDatastoreContextBuilder().shardManagerPersistenceId("shard-manager-config-" + memberName);
- node.configDataStore = node.kit.setupDistributedDataStore("config_" + testName, moduleShardsConfig,
- true, schemaContext, waitForshardLeader);
+ node.configDataStore = node.kit.setupAbstractDataStore(DistributedDataStore.class,
+ "config_" + testName, moduleShardsConfig, true, schemaContext, waitForshardLeader);
if (createOperDatastore) {
node.kit.getDatastoreContextBuilder().shardManagerPersistenceId("shard-manager-oper-" + memberName);
- node.operDataStore = node.kit.setupDistributedDataStore("oper_" + testName, moduleShardsConfig,
- true, schemaContext, waitForshardLeader);
+ node.operDataStore = node.kit.setupAbstractDataStore(DistributedDataStore.class,
+ "oper_" + testName, moduleShardsConfig, true, schemaContext, waitForshardLeader);
}
members.add(node);
import org.opendaylight.controller.cluster.raft.utils.InMemoryJournal;
import org.opendaylight.controller.cluster.raft.utils.InMemorySnapshotStore;
import org.opendaylight.controller.md.cluster.datastore.model.SchemaContextHelper;
-import org.opendaylight.mdsal.eos.common.api.CandidateAlreadyRegisteredException;
import org.opendaylight.mdsal.eos.common.api.EntityOwnershipState;
import org.opendaylight.mdsal.eos.dom.api.DOMEntity;
import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipCandidateRegistration;
* Reproduces bug <a href="https://bugs.opendaylight.org/show_bug.cgi?id=4554">4554</a>.
*/
@Test
- public void testCloseCandidateRegistrationInQuickSuccession() throws CandidateAlreadyRegisteredException {
+ public void testCloseCandidateRegistrationInQuickSuccession() throws Exception {
String name = "testCloseCandidateRegistrationInQuickSuccession";
MemberNode leaderNode = MemberNode.builder(memberNodes).akkaConfig("Member1").testName(name)
.moduleShardsConfig(MODULE_SHARDS_CONFIG).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false)
InMemorySnapshotStore.clear();
}
- private void initEmptyDatastores() {
+ private void initEmptyDatastores() throws Exception {
leaderTestKit = new IntegrationTestKit(leaderSystem, leaderDatastoreContextBuilder);
- leaderConfigDatastore = (DistributedDataStore) leaderTestKit.setupDistributedDataStore(
+ leaderConfigDatastore = leaderTestKit.setupDistributedDataStore(
"config", MODULE_SHARDS_CONFIG, true,
SchemaContextHelper.distributedShardedDOMDataTreeSchemaContext());
- leaderOperDatastore = (DistributedDataStore) leaderTestKit.setupDistributedDataStore(
+ leaderOperDatastore = leaderTestKit.setupDistributedDataStore(
"operational", MODULE_SHARDS_CONFIG, true,
SchemaContextHelper.distributedShardedDOMDataTreeSchemaContext());
followerTestKit = new IntegrationTestKit(followerSystem, followerDatastoreContextBuilder);
- followerConfigDatastore = (DistributedDataStore) followerTestKit.setupDistributedDataStore(
+ followerConfigDatastore = followerTestKit.setupDistributedDataStore(
"config", MODULE_SHARDS_CONFIG, true, SchemaContextHelper.distributedShardedDOMDataTreeSchemaContext());
- followerOperDatastore = (DistributedDataStore) followerTestKit.setupDistributedDataStore(
+ followerOperDatastore = followerTestKit.setupDistributedDataStore(
"operational", MODULE_SHARDS_CONFIG, true,
SchemaContextHelper.distributedShardedDOMDataTreeSchemaContext());
InMemorySnapshotStore.clear();
}
- private void initEmptyDatastores() {
+ private void initEmptyDatastores() throws Exception {
leaderTestKit = new IntegrationTestKit(leaderSystem, leaderDatastoreContextBuilder);
- leaderDistributedDataStore = (DistributedDataStore) leaderTestKit.setupDistributedDataStore(
+ leaderDistributedDataStore = leaderTestKit.setupDistributedDataStore(
"config", MODULE_SHARDS_CONFIG, "empty-modules.conf", true,
SchemaContextHelper.distributedShardedDOMDataTreeSchemaContext());
- operDistributedDatastore = (DistributedDataStore) leaderTestKit.setupDistributedDataStore(
+ operDistributedDatastore = leaderTestKit.setupDistributedDataStore(
"operational", MODULE_SHARDS_CONFIG, "empty-modules.conf",true,
SchemaContextHelper.distributedShardedDOMDataTreeSchemaContext());