use of org.opendaylight.controller.cluster.access.concepts.Response in project controller by opendaylight.
the class TransmittingTransmitQueueTest method testTransmit.
@Test
@Override
public void testTransmit() throws Exception {
final Request<?, ?> request = new TransactionPurgeRequest(TRANSACTION_IDENTIFIER, 0L, probe.ref());
final Consumer<Response<?, ?>> callback = createConsumerMock();
final long now = now();
final ConnectionEntry entry = new ConnectionEntry(request, callback, now);
Optional<TransmittedConnectionEntry> transmitted = queue.transmit(entry, now);
assertTrue(transmitted.isPresent());
assertEquals(request, transmitted.get().getRequest());
assertEquals(callback, transmitted.get().getCallback());
final RequestEnvelope requestEnvelope = probe.expectMsgClass(RequestEnvelope.class);
assertEquals(request, requestEnvelope.getMessage());
transmitted = queue.transmit(new ConnectionEntry(new TransactionPurgeRequest(TRANSACTION_IDENTIFIER, 1L, probe.ref()), callback, now), now);
assertTrue(transmitted.isPresent());
}
use of org.opendaylight.controller.cluster.access.concepts.Response in project controller by opendaylight.
the class RemoteProxyTransaction method handleForwardedRequest.
void handleForwardedRequest(final TransactionRequest<?> request, final Consumer<Response<?, ?>> callback) {
if (request instanceof ModifyTransactionRequest) {
handleForwardedModifyTransactionRequest(callback, (ModifyTransactionRequest) request);
} else if (request instanceof ReadTransactionRequest) {
ensureFlushedBuider();
sendRequest(new ReadTransactionRequest(getIdentifier(), nextSequence(), localActor(), ((ReadTransactionRequest) request).getPath(), isSnapshotOnly()), resp -> {
recordFinishedRequest(resp);
callback.accept(resp);
});
} else if (request instanceof ExistsTransactionRequest) {
ensureFlushedBuider();
sendRequest(new ExistsTransactionRequest(getIdentifier(), nextSequence(), localActor(), ((ExistsTransactionRequest) request).getPath(), isSnapshotOnly()), resp -> {
recordFinishedRequest(resp);
callback.accept(resp);
});
} else if (request instanceof TransactionPreCommitRequest) {
ensureFlushedBuider();
final TransactionRequest<?> tmp = new TransactionPreCommitRequest(getIdentifier(), nextSequence(), localActor());
sendRequest(tmp, resp -> {
recordSuccessfulRequest(tmp);
callback.accept(resp);
});
} else if (request instanceof TransactionDoCommitRequest) {
ensureFlushedBuider();
sendRequest(new TransactionDoCommitRequest(getIdentifier(), nextSequence(), localActor()), callback);
} else if (request instanceof TransactionAbortRequest) {
ensureFlushedBuider();
sendDoAbort(callback);
} else if (request instanceof TransactionPurgeRequest) {
enqueuePurge(callback);
} else {
throw new IllegalArgumentException("Unhandled request {}" + request);
}
}
use of org.opendaylight.controller.cluster.access.concepts.Response in project controller by opendaylight.
the class AbstractClientConnectionTest method testSendRequestReceiveResponse.
@Test
public void testSendRequestReceiveResponse() throws Exception {
final Consumer<Response<?, ?>> callback = mock(Consumer.class);
final Request<?, ?> request = createRequest(replyToProbe.ref());
connection.sendRequest(request, callback);
final RequestEnvelope requestEnvelope = backendProbe.expectMsgClass(RequestEnvelope.class);
Assert.assertEquals(request, requestEnvelope.getMessage());
final LocalHistoryIdentifier historyId = new LocalHistoryIdentifier(CLIENT_ID, 0L);
final RequestSuccess<?, ?> message = new TransactionAbortSuccess(new TransactionIdentifier(historyId, 0L), 0L);
final ResponseEnvelope<?> envelope = new SuccessEnvelope(message, 0L, 0L, 0L);
connection.receiveResponse(envelope);
verify(callback, timeout(1000)).accept(isA(TransactionAbortSuccess.class));
}
use of org.opendaylight.controller.cluster.access.concepts.Response in project controller by opendaylight.
the class AbstractTransmitQueueTest method testPoison.
@Test
public void testPoison() throws Exception {
final Request<?, ?> request = new TransactionPurgeRequest(TRANSACTION_IDENTIFIER, 0L, probe.ref());
final Consumer<Response<?, ?>> callback = createConsumerMock();
final long now = Ticker.systemTicker().read();
queue.enqueueOrForward(new ConnectionEntry(request, callback, now), now);
queue.poison(new RuntimeRequestException("fail", new RuntimeException("fail")));
verify(callback).accept(any(TransactionFailure.class));
Assert.assertTrue(queue.isEmpty());
}
use of org.opendaylight.controller.cluster.access.concepts.Response in project controller by opendaylight.
the class ConnectedClientConnectionTest method testSendSliceableMessageRequest.
@SuppressWarnings("unchecked")
@Test
public void testSendSliceableMessageRequest() {
final ClientActorConfig config = AccessClientUtil.newMockClientActorConfig();
doReturn(5).when(config).getMaximumMessageSliceSize();
context = new ClientActorContext(contextProbe.ref(), PERSISTENCE_ID, system, CLIENT_ID, config);
connection = createConnection();
final Consumer<Response<?, ?>> callback = mock(Consumer.class);
final TransactionIdentifier identifier = new TransactionIdentifier(new LocalHistoryIdentifier(CLIENT_ID, 0L), 0L);
ModifyTransactionRequestBuilder reqBuilder = new ModifyTransactionRequestBuilder(identifier, replyToProbe.ref());
reqBuilder.addModification(new TransactionWrite(YangInstanceIdentifier.EMPTY, Builders.containerBuilder().withNodeIdentifier(YangInstanceIdentifier.NodeIdentifier.create(QName.create("namespace", "localName"))).build()));
reqBuilder.setSequence(0L);
final Request<?, ?> request = reqBuilder.build();
connection.sendRequest(request, callback);
backendProbe.expectMsgClass(MessageSlice.class);
}
Aggregations