X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatabroker%2Factors%2Fdds%2FClientLocalHistoryTest.java;h=298470021ee20c04c35f4fdb963c5f10a04cbca9;hb=refs%2Fchanges%2F61%2F96761%2F2;hp=8aadd86ddbb41ce4c08958e7276473540dc4828f;hpb=ca5129914385dd43bf4c2af2757374878e785979;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/ClientLocalHistoryTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/ClientLocalHistoryTest.java index 8aadd86ddb..298470021e 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/ClientLocalHistoryTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/ClientLocalHistoryTest.java @@ -7,23 +7,29 @@ */ package org.opendaylight.controller.cluster.databroker.actors.dds; -import static org.opendaylight.controller.cluster.databroker.actors.dds.TestUtils.CLIENT_ID; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.endsWith; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; import akka.actor.ActorSystem; -import akka.testkit.JavaTestKit; import akka.testkit.TestProbe; +import akka.testkit.javadsl.TestKit; import org.junit.After; -import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.opendaylight.controller.cluster.access.client.AbstractClientConnection; import org.opendaylight.controller.cluster.access.client.AccessClientUtil; import org.opendaylight.controller.cluster.access.client.ClientActorContext; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; -import org.opendaylight.controller.cluster.datastore.utils.ActorContext; +import org.opendaylight.controller.cluster.datastore.utils.ActorUtils; +@RunWith(MockitoJUnitRunner.StrictStubs.class) public class ClientLocalHistoryTest extends AbstractClientHistoryTest { private ActorSystem system; private AbstractDataStoreClientBehavior behavior; @@ -36,24 +42,22 @@ public class ClientLocalHistoryTest extends AbstractClientHistoryTest clientConnection = behavior.getConnection(0L); final ProxyHistory historyProxy = object().createHistoryProxy(HISTORY_ID, clientConnection); - Assert.assertEquals(object().getIdentifier(), historyProxy.getIdentifier()); + assertEquals(object().getIdentifier(), historyProxy.getIdentifier()); } @Override @Test - public void testDoCreateSnapshot() throws Exception { + public void testDoCreateSnapshot() { final ClientSnapshot clientSnapshot = object().doCreateSnapshot(); - Assert.assertEquals(new TransactionIdentifier(object().getIdentifier(), object().nextTx()).getHistoryId(), + assertEquals(new TransactionIdentifier(object().getIdentifier(), object().nextTx()).getHistoryId(), clientSnapshot.getIdentifier().getHistoryId()); } @Override @Test - public void testOnTransactionComplete() throws Exception { - final ClientTransaction transaction = object().createTransaction(); + public void testOnTransactionComplete() { + final ClientTransaction tx = object().createTransaction(); // make transaction ready - object().onTransactionReady(transaction, cohort); + object().onTransactionReady(tx, cohort); // state should be set to IDLE - Assert.assertEquals(AbstractClientHistory.State.IDLE, object.state()); + assertEquals(AbstractClientHistory.State.IDLE, object.state()); // complete transaction - object().onTransactionComplete(transaction.getIdentifier()); + object().onTransactionComplete(tx.getIdentifier()); // state is still IDLE - Assert.assertEquals(AbstractClientHistory.State.IDLE, object.state()); + assertEquals(AbstractClientHistory.State.IDLE, object.state()); } @Override @Test - public void testOnTransactionReady() throws Exception { - final AbstractTransactionCommitCohort result = object().onTransactionReady( - object().createTransaction(), cohort); - Assert.assertEquals(result, cohort); + public void testOnTransactionReady() { + final AbstractTransactionCommitCohort result = object().onTransactionReady(object().createTransaction(), + cohort); + assertEquals(result, cohort); } @Override - @Test(expected = IllegalStateException.class) - public void testOnTransactionReadyDuplicate() throws Exception { - final ClientTransaction transaction = object().createTransaction(); - object().onTransactionReady(transaction, cohort); - object().onTransactionReady(transaction, cohort); + @Test + public void testOnTransactionReadyDuplicate() { + final ClientTransaction tx = object().createTransaction(); + object().onTransactionReady(tx, cohort); + final IllegalStateException ise = assertThrows(IllegalStateException.class, + () -> object().onTransactionReady(tx, cohort)); + assertThat(ise.getMessage(), containsString(" is idle when readying transaction ")); } @Test - public void testOnTransactionReadyAndComplete() throws Exception { + public void testOnTransactionReadyAndComplete() { object().updateState(AbstractClientHistory.State.IDLE, AbstractClientHistory.State.TX_OPEN); final AbstractTransactionCommitCohort transactionCommitCohort = object().onTransactionReady(transaction, cohort); - Assert.assertEquals(cohort, transactionCommitCohort); + assertEquals(cohort, transactionCommitCohort); } @Test - public void testOnTransactionReadyAndCompleteStateClosed() throws Exception { + public void testOnTransactionReadyAndCompleteStateClosed() { object().updateState(AbstractClientHistory.State.IDLE, AbstractClientHistory.State.CLOSED); final AbstractTransactionCommitCohort transactionCommitCohort = object().onTransactionReady(transaction, cohort); - Assert.assertEquals(cohort, transactionCommitCohort); + assertEquals(cohort, transactionCommitCohort); } - @Test(expected = IllegalStateException.class) - public void testOnTransactionReadyAndCompleteIdleFail() throws Exception { - object().onTransactionReady(transaction, cohort); + @Test + public void testOnTransactionReadyAndCompleteIdleFail() { + final IllegalStateException ise = assertThrows(IllegalStateException.class, + () -> object().onTransactionReady(transaction, cohort)); + assertThat(ise.getMessage(), endsWith(" is idle when readying transaction null")); } -} \ No newline at end of file +}