/*
- * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others. All rights reserved.
+ * Copyright (c) 2014, 2017 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicReference;
import org.junit.After;
import org.junit.Before;
public void testWriteTransactionWithSingleShard() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
- try (final AbstractDataStore dataStore = setupAbstractDataStore(
+ try (AbstractDataStore dataStore = setupAbstractDataStore(
testParameter, "transactionIntegrationTest", "test-1")) {
testWriteTransaction(dataStore, TestModel.TEST_PATH,
public void testWriteTransactionWithMultipleShards() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
- try (final AbstractDataStore dataStore = setupAbstractDataStore(
+ try (AbstractDataStore dataStore = setupAbstractDataStore(
testParameter, "testWriteTransactionWithMultipleShards", "cars-1", "people-1")) {
DOMStoreWriteTransaction writeTx = dataStore.newWriteOnlyTransaction();
public void testReadWriteTransactionWithSingleShard() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
- try (final AbstractDataStore dataStore = setupAbstractDataStore(
+ try (AbstractDataStore dataStore = setupAbstractDataStore(
testParameter, "testReadWriteTransactionWithSingleShard", "test-1")) {
// 1. Create a read-write Tx
public void testReadWriteTransactionWithMultipleShards() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
- try (final AbstractDataStore dataStore = setupAbstractDataStore(
+ try (AbstractDataStore dataStore = setupAbstractDataStore(
testParameter, "testReadWriteTransactionWithMultipleShards", "cars-1", "people-1")) {
DOMStoreReadWriteTransaction readWriteTx = dataStore.newReadWriteTransaction();
public void testSingleTransactionsWritesInQuickSuccession() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
- try (final AbstractDataStore dataStore = setupAbstractDataStore(
+ try (AbstractDataStore dataStore = setupAbstractDataStore(
testParameter, "testSingleTransactionsWritesInQuickSuccession", "cars-1")) {
final DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
final CountDownLatch blockRecoveryLatch = new CountDownLatch(1);
InMemoryJournal.addBlockReadMessagesLatch(persistentID, blockRecoveryLatch);
- try (final AbstractDataStore dataStore = setupAbstractDataStore(
+ try (AbstractDataStore dataStore = setupAbstractDataStore(
testParameter, testName, false, shardName)) {
// Create the write Tx
final CountDownLatch blockRecoveryLatch = new CountDownLatch(1);
InMemoryJournal.addBlockReadMessagesLatch(persistentID, blockRecoveryLatch);
- try (final AbstractDataStore dataStore = setupAbstractDataStore(
+ try (AbstractDataStore dataStore = setupAbstractDataStore(
testParameter, testName, false, shardName)) {
// Create the read-write Tx
InMemoryJournal.addEntry(persistentID, 1, "Dummy data so akka will read from persistence");
- try (final AbstractDataStore dataStore = setupAbstractDataStore(
+ try (AbstractDataStore dataStore = setupAbstractDataStore(
testParameter, testName, false, shardName)) {
// Create the read-write Tx
datastoreContextBuilder.shardHeartbeatIntervalInMillis(100).shardElectionTimeoutFactor(1)
.shardInitializationTimeout(200, TimeUnit.MILLISECONDS);
- try (final AbstractDataStore dataStore = setupAbstractDataStore(
+ try (AbstractDataStore dataStore = setupAbstractDataStore(
testParameter, testName, false, shardName)) {
final Object result = dataStore.getActorContext().executeOperation(
assertTrue("Expected LocalShardFound. Actual: " + result, result instanceof LocalShardFound);
// Create the write Tx.
- try (final DOMStoreWriteTransaction writeTx = writeOnly ? dataStore.newWriteOnlyTransaction()
- : dataStore.newReadWriteTransaction()) {
+ DOMStoreWriteTransaction writeTxToClose = null;
+ try {
+ writeTxToClose = writeOnly ? dataStore.newWriteOnlyTransaction()
+ : dataStore.newReadWriteTransaction();
+ final DOMStoreWriteTransaction writeTx = writeTxToClose;
assertNotNull("newReadWriteTransaction returned null", writeTx);
// Do some modifications and ready the Tx on a separate
txCohort.get().canCommit().get(5, TimeUnit.SECONDS);
fail("Expected NoShardLeaderException");
} catch (final ExecutionException e) {
- Throwables.propagate(Throwables.getRootCause(e));
+ assertTrue(Throwables.getRootCause(e) instanceof NoShardLeaderException);
+ assertEquals(DistributedDataStore.class, testParameter);
+ } catch (TimeoutException e) {
+ // ClientBackedDataStore doesn't set cause to ExecutionException, future just time outs
+ assertEquals(ClientBackedDataStore.class, testParameter);
+ }
+ } finally {
+ try {
+ if (writeTxToClose != null) {
+ writeTxToClose.close();
+ }
+ } catch (Exception e) {
+ // FIXME TransactionProxy.close throws IllegalStateException:
+ // Transaction is ready, it cannot be closed
}
}
}
};
}
- @Test(expected = NoShardLeaderException.class)
+ @Test
public void testWriteOnlyTransactionCommitFailureWithNoShardLeader() throws Exception {
datastoreContextBuilder.writeOnlyTransactionOptimizationsEnabled(true);
testTransactionCommitFailureWithNoShardLeader(true, "testWriteOnlyTransactionCommitFailureWithNoShardLeader");
}
- @Test(expected = NoShardLeaderException.class)
+ @Test
public void testReadWriteTransactionCommitFailureWithNoShardLeader() throws Exception {
testTransactionCommitFailureWithNoShardLeader(false, "testReadWriteTransactionCommitFailureWithNoShardLeader");
}
public void testTransactionAbort() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
- try (final AbstractDataStore dataStore = setupAbstractDataStore(
+ try (AbstractDataStore dataStore = setupAbstractDataStore(
testParameter, "transactionAbortIntegrationTest", "test-1")) {
final DOMStoreWriteTransaction writeTx = dataStore.newWriteOnlyTransaction();
public void testTransactionChainWithSingleShard() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
- try (final AbstractDataStore dataStore = setupAbstractDataStore(
+ try (AbstractDataStore dataStore = setupAbstractDataStore(
testParameter, "testTransactionChainWithSingleShard", "test-1")) {
// 1. Create a Tx chain and write-only Tx
public void testTransactionChainWithMultipleShards() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
- try (final AbstractDataStore dataStore = setupAbstractDataStore(
+ try (AbstractDataStore dataStore = setupAbstractDataStore(
testParameter, "testTransactionChainWithMultipleShards", "cars-1", "people-1")) {
final DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
public void testCreateChainedTransactionsInQuickSuccession() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
- try (final AbstractDataStore dataStore = setupAbstractDataStore(
+ try (AbstractDataStore dataStore = setupAbstractDataStore(
testParameter, "testCreateChainedTransactionsInQuickSuccession", "cars-1")) {
final ConcurrentDOMDataBroker broker = new ConcurrentDOMDataBroker(
public void testCreateChainedTransactionAfterEmptyTxReadied() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
- try (final AbstractDataStore dataStore = setupAbstractDataStore(
+ try (AbstractDataStore dataStore = setupAbstractDataStore(
testParameter, "testCreateChainedTransactionAfterEmptyTxReadied", "test-1")) {
final DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
public void testCreateChainedTransactionWhenPreviousNotReady() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
- try (final AbstractDataStore dataStore = setupAbstractDataStore(
+ try (AbstractDataStore dataStore = setupAbstractDataStore(
testParameter, "testCreateChainedTransactionWhenPreviousNotReady", "test-1")) {
final DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
public void testChainWithReadOnlyTxAfterPreviousReady() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
- try (final AbstractDataStore dataStore = setupAbstractDataStore(
+ try (AbstractDataStore dataStore = setupAbstractDataStore(
testParameter, "testChainWithReadOnlyTxAfterPreviousReady", "test-1")) {
final DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
public void testChainedTransactionFailureWithSingleShard() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
- try (final AbstractDataStore dataStore = setupAbstractDataStore(
+ try (AbstractDataStore dataStore = setupAbstractDataStore(
testParameter, "testChainedTransactionFailureWithSingleShard", "cars-1")) {
final ConcurrentDOMDataBroker broker = new ConcurrentDOMDataBroker(
public void testChainedTransactionFailureWithMultipleShards() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
- try (final AbstractDataStore dataStore = setupAbstractDataStore(
+ try (AbstractDataStore dataStore = setupAbstractDataStore(
testParameter, "testChainedTransactionFailureWithMultipleShards", "cars-1", "people-1")) {
final ConcurrentDOMDataBroker broker = new ConcurrentDOMDataBroker(
public void testChangeListenerRegistration() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
- try (final AbstractDataStore dataStore = setupAbstractDataStore(
+ try (AbstractDataStore dataStore = setupAbstractDataStore(
testParameter, "testChangeListenerRegistration", "test-1")) {
testWriteTransaction(dataStore, TestModel.TEST_PATH,
public void testDataTreeChangeListenerRegistration() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
- try (final AbstractDataStore dataStore = setupAbstractDataStore(
+ try (AbstractDataStore dataStore = setupAbstractDataStore(
testParameter, "testDataTreeChangeListenerRegistration", "test-1")) {
testWriteTransaction(dataStore, TestModel.TEST_PATH,
new DatastoreSnapshot.ShardSnapshot("cars", carsSnapshot),
new DatastoreSnapshot.ShardSnapshot("people", peopleSnapshot)));
- try (final AbstractDataStore dataStore = setupAbstractDataStore(
+ try (AbstractDataStore dataStore = setupAbstractDataStore(
testParameter, name, "module-shards-member1.conf", true, "cars", "people")) {
final DOMStoreReadTransaction readTx = dataStore.newReadOnlyTransaction();
MetadataShardDataTreeSnapshot shardSnapshot = new MetadataShardDataTreeSnapshot(root);
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
- try (final DataOutputStream dos = new DataOutputStream(bos)) {
+ try (DataOutputStream dos = new DataOutputStream(bos)) {
PayloadVersion.BORON.writeTo(dos);
try (ObjectOutputStream oos = new ObjectOutputStream(dos)) {
oos.writeObject(shardSnapshot);