*/
package org.opendaylight.controller.cluster.databroker.actors.dds;
-import static org.hamcrest.CoreMatchers.both;
+import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.core.Is.isA;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import akka.actor.ActorSystem;
-import akka.testkit.JavaTestKit;
import akka.testkit.TestProbe;
+import akka.testkit.javadsl.TestKit;
import com.google.common.base.Ticker;
import com.google.common.primitives.UnsignedLong;
import java.util.ArrayList;
private TestProbe backendProbe;
private TestProbe clientContextProbe;
private TransactionTester<T> tester;
+ protected ClientActorContext context;
protected T transaction;
@Before
- public void setUp() throws Exception {
+ public void setUp() {
MockitoAnnotations.initMocks(this);
system = ActorSystem.apply();
clientContextProbe = new TestProbe(system, "clientContext");
backendProbe = new TestProbe(system, "backend");
- final ClientActorContext context =
- AccessClientUtil.createClientActorContext(system, clientContextProbe.ref(), CLIENT_ID, PERSISTENCE_ID);
+ context = AccessClientUtil.createClientActorContext(system, clientContextProbe.ref(), CLIENT_ID,
+ PERSISTENCE_ID);
final ShardBackendInfo backend = new ShardBackendInfo(backendProbe.ref(), 0L, ABIVersion.BORON,
"default", UnsignedLong.ZERO, Optional.empty(), 3);
final AbstractClientConnection<ShardBackendInfo> connection =
tester = new TransactionTester<>(transaction, connection, backendProbe);
}
+ @SuppressWarnings("checkstyle:hiddenField")
protected abstract T createTransaction(ProxyHistory parent, TransactionIdentifier id, DataTreeSnapshot snapshot);
@After
- public void tearDown() throws Exception {
- JavaTestKit.shutdownActorSystem(system);
+ public void tearDown() {
+ TestKit.shutdownActorSystem(system);
}
@Test
public abstract void testRead() throws Exception;
@Test
- public abstract void testWrite() throws Exception;
+ public abstract void testWrite();
@Test
- public abstract void testMerge() throws Exception;
+ public abstract void testMerge();
@Test
- public abstract void testDelete() throws Exception;
+ public abstract void testDelete();
@Test
public abstract void testDirectCommit() throws Exception;
@Test
- public abstract void testCanCommit() throws Exception;
+ public abstract void testCanCommit();
@Test
- public abstract void testPreCommit() throws Exception;
+ public abstract void testPreCommit();
@Test
- public abstract void testDoCommit() throws Exception;
+ public abstract void testDoCommit();
@Test
- public abstract void testForwardToRemoteAbort() throws Exception;
+ public abstract void testForwardToRemoteAbort();
@Test
- public abstract void testForwardToRemoteCommit() throws Exception;
+ public abstract void testForwardToRemoteCommit();
@Test
- public void testAbortVotingFuture() throws Exception {
+ public void testAbortVotingFuture() {
testRequestResponse(f -> transaction.abort(f), TransactionAbortRequest.class, TransactionAbortSuccess::new);
}
@Test
- public void testForwardToRemotePurge() throws Exception {
+ public void testForwardToRemotePurge() {
final TestProbe probe = new TestProbe(system);
final TransactionPurgeRequest request = new TransactionPurgeRequest(TRANSACTION_ID, 0L, probe.ref());
testForwardToRemote(request, TransactionPurgeRequest.class);
}
@Test
- public void testReplayMessages() throws Exception {
+ public void testReplayMessages() {
final TestProbe probe = new TestProbe(system);
final List<ConnectionEntry> entries = new ArrayList<>();
final Consumer<Response<?, ?>> callback = createCallbackMock();
new ReadTransactionRequest(TRANSACTION_ID, 1L, probe.ref(), PATH_1, true);
transaction.recordSuccessfulRequest(successful2);
transaction.startReconnect();
- transaction.replayMessages(successor.getTransaction(), entries);
+
+ final ProxyHistory mockSuccessor = mock(ProxyHistory.class);
+ when(mockSuccessor.createTransactionProxy(TRANSACTION_ID, transaction.isSnapshotOnly(), false))
+ .thenReturn(successor.getTransaction());
+
+ transaction.replayMessages(mockSuccessor, entries);
final ModifyTransactionRequest transformed = successor.expectTransactionRequest(ModifyTransactionRequest.class);
Assert.assertNotNull(transformed);
protected void checkModifications(final ModifyTransactionRequest modifyRequest) {
final List<TransactionModification> modifications = modifyRequest.getModifications();
Assert.assertEquals(3, modifications.size());
- Assert.assertThat(modifications, hasItem(both(isA(TransactionWrite.class)).and(hasPath(PATH_1))));
- Assert.assertThat(modifications, hasItem(both(isA(TransactionMerge.class)).and(hasPath(PATH_2))));
- Assert.assertThat(modifications, hasItem(both(isA(TransactionDelete.class)).and(hasPath(PATH_3))));
+ Assert.assertThat(modifications, hasItem(allOf(isA(TransactionWrite.class), hasPath(PATH_1))));
+ Assert.assertThat(modifications, hasItem(allOf(isA(TransactionMerge.class), hasPath(PATH_2))));
+ Assert.assertThat(modifications, hasItem(allOf(isA(TransactionDelete.class), hasPath(PATH_3))));
}
- protected void testRequestResponse(final Consumer<VotingFuture<Void>> consumer,
- final Class<? extends TransactionRequest<?>> expectedRequest,
- final BiFunction<TransactionIdentifier, Long, TransactionSuccess<?>> replySupplier)
- throws Exception {
+ @SuppressWarnings("checkstyle:hiddenField")
+ protected <R extends TransactionRequest<R>> void testRequestResponse(final Consumer<VotingFuture<Void>> consumer,
+ final Class<R> expectedRequest,
+ final BiFunction<TransactionIdentifier, Long, TransactionSuccess<?>> replySupplier) {
final TransactionTester<T> tester = getTester();
final VotingFuture<Void> future = mock(VotingFuture.class);
transaction.seal();
verify(future).voteYes();
}
- protected <T extends TransactionRequest<?>> T testHandleForwardedRemoteRequest(final T request) throws Exception {
+ protected <R extends TransactionRequest<R>> R testHandleForwardedRemoteRequest(final R request) {
transaction.handleReplayedRemoteRequest(request, createCallbackMock(), Ticker.systemTicker().read());
final RequestEnvelope envelope = backendProbe.expectMsgClass(RequestEnvelope.class);
- final T received = (T) envelope.getMessage();
+ final R received = (R) envelope.getMessage();
Assert.assertTrue(received.getClass().equals(request.getClass()));
Assert.assertEquals(TRANSACTION_ID, received.getTarget());
Assert.assertEquals(clientContextProbe.ref(), received.getReplyTo());
return received;
}
- protected <T extends TransactionRequest<?>> T testForwardToRemote(final TransactionRequest<?> toForward,
- final Class<T> expectedMessageClass) {
+ protected <R extends TransactionRequest<R>> R testForwardToRemote(final TransactionRequest<?> toForward,
+ final Class<R> expectedMessageClass) {
final Consumer<Response<?, ?>> callback = createCallbackMock();
final TransactionTester<RemoteProxyTransaction> transactionTester = createRemoteProxyTransactionTester();
final RemoteProxyTransaction successor = transactionTester.getTransaction();
return new TestProbe(system);
}
+ @SuppressWarnings("checkstyle:hiddenField")
protected TransactionTester<LocalReadWriteProxyTransaction> createLocalProxy() {
final TestProbe backendProbe = new TestProbe(system, "backend2");
final TestProbe clientContextProbe = new TestProbe(system, "clientContext2");
return new TransactionTester<>(tx, connection, backendProbe);
}
+ @SuppressWarnings("checkstyle:hiddenField")
protected TransactionTester<RemoteProxyTransaction> createRemoteProxyTransactionTester() {
final TestProbe clientContextProbe = new TestProbe(system, "remoteClientContext");
final TestProbe backendProbe = new TestProbe(system, "remoteBackend");
AccessClientUtil.createConnectedConnection(context, 0L, backend);
final ProxyHistory proxyHistory = ProxyHistory.createClient(history, connection, HISTORY_ID);
final RemoteProxyTransaction transaction =
- new RemoteProxyTransaction(proxyHistory, TRANSACTION_ID, false, false);
+ new RemoteProxyTransaction(proxyHistory, TRANSACTION_ID, false, false, false);
return new TransactionTester<>(transaction, connection, backendProbe);
}
}