use of org.opendaylight.controller.cluster.access.concepts.RequestEnvelope in project controller by opendaylight.
the class AbstractClientHandleTest method backendRespondToRequest.
/**
* Checks, whether backend actor has received request of expected class wrapped in RequestEnvelope.
* Then given response wrapped in ResponseEnvelope is sent.
*
* @param expectedRequestClass expected request class
* @param response response
* @param <R> expected request type
* @return request message
*/
protected <R extends Request<?, R>> R backendRespondToRequest(final Class<R> expectedRequestClass, final Response<?, ?> response) {
final RequestEnvelope envelope = backendProbe.expectMsgClass(RequestEnvelope.class);
Assert.assertEquals(expectedRequestClass, envelope.getMessage().getClass());
final AbstractClientConnection<ShardBackendInfo> connection = client.getConnection(0L);
final long sessionId = envelope.getSessionId();
final long txSequence = envelope.getTxSequence();
final long executionTime = 0L;
if (response instanceof RequestSuccess) {
final RequestSuccess<?, ?> success = (RequestSuccess<?, ?>) response;
final SuccessEnvelope responseEnvelope = new SuccessEnvelope(success, sessionId, txSequence, executionTime);
AccessClientUtil.completeRequest(connection, responseEnvelope);
} else if (response instanceof RequestFailure) {
final RequestFailure<?, ?> fail = (RequestFailure<?, ?>) response;
final FailureEnvelope responseEnvelope = new FailureEnvelope(fail, sessionId, txSequence, executionTime);
AccessClientUtil.completeRequest(connection, responseEnvelope);
}
return expectedRequestClass.cast(envelope.getMessage());
}
use of org.opendaylight.controller.cluster.access.concepts.RequestEnvelope in project controller by opendaylight.
the class AbstractProxyTransactionTest method testHandleForwardedRemoteRequest.
protected <R extends TransactionRequest<R>> R testHandleForwardedRemoteRequest(final R request) throws Exception {
transaction.handleReplayedRemoteRequest(request, createCallbackMock(), Ticker.systemTicker().read());
final RequestEnvelope envelope = backendProbe.expectMsgClass(RequestEnvelope.class);
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;
}
use of org.opendaylight.controller.cluster.access.concepts.RequestEnvelope in project controller by opendaylight.
the class Shard method handleNonRaftCommand.
@Override
protected void handleNonRaftCommand(final Object message) {
try (MessageTracker.Context context = appendEntriesReplyTracker.received(message)) {
final Optional<Error> maybeError = context.error();
if (maybeError.isPresent()) {
LOG.trace("{} : AppendEntriesReply failed to arrive at the expected interval {}", persistenceId(), maybeError.get());
}
store.resetTransactionBatch();
if (message instanceof RequestEnvelope) {
handleRequestEnvelope((RequestEnvelope) message);
} else if (MessageAssembler.isHandledMessage(message)) {
handleRequestAssemblerMessage(message);
} else if (message instanceof ConnectClientRequest) {
handleConnectClient((ConnectClientRequest) message);
} else if (CreateTransaction.isSerializedType(message)) {
handleCreateTransaction(message);
} else if (message instanceof BatchedModifications) {
handleBatchedModifications((BatchedModifications) message);
} else if (message instanceof ForwardedReadyTransaction) {
handleForwardedReadyTransaction((ForwardedReadyTransaction) message);
} else if (message instanceof ReadyLocalTransaction) {
handleReadyLocalTransaction((ReadyLocalTransaction) message);
} else if (CanCommitTransaction.isSerializedType(message)) {
handleCanCommitTransaction(CanCommitTransaction.fromSerializable(message));
} else if (CommitTransaction.isSerializedType(message)) {
handleCommitTransaction(CommitTransaction.fromSerializable(message));
} else if (AbortTransaction.isSerializedType(message)) {
handleAbortTransaction(AbortTransaction.fromSerializable(message));
} else if (CloseTransactionChain.isSerializedType(message)) {
closeTransactionChain(CloseTransactionChain.fromSerializable(message));
} else if (message instanceof RegisterChangeListener) {
changeSupport.onMessage((RegisterChangeListener) message, isLeader(), hasLeader());
} else if (message instanceof RegisterDataTreeChangeListener) {
treeChangeSupport.onMessage((RegisterDataTreeChangeListener) message, isLeader(), hasLeader());
} else if (message instanceof UpdateSchemaContext) {
updateSchemaContext((UpdateSchemaContext) message);
} else if (message instanceof PeerAddressResolved) {
PeerAddressResolved resolved = (PeerAddressResolved) message;
setPeerAddress(resolved.getPeerId(), resolved.getPeerAddress());
} else if (TX_COMMIT_TIMEOUT_CHECK_MESSAGE.equals(message)) {
commitTimeoutCheck();
} else if (message instanceof DatastoreContext) {
onDatastoreContext((DatastoreContext) message);
} else if (message instanceof RegisterRoleChangeListener) {
roleChangeNotifier.get().forward(message, context());
} else if (message instanceof FollowerInitialSyncUpStatus) {
shardMBean.setFollowerInitialSyncStatus(((FollowerInitialSyncUpStatus) message).isInitialSyncDone());
context().parent().tell(message, self());
} else if (GET_SHARD_MBEAN_MESSAGE.equals(message)) {
sender().tell(getShardMBean(), self());
} else if (message instanceof GetShardDataTree) {
sender().tell(store.getDataTree(), self());
} else if (message instanceof ServerRemoved) {
context().parent().forward(message, context());
} else if (ShardTransactionMessageRetrySupport.TIMER_MESSAGE_CLASS.isInstance(message)) {
messageRetrySupport.onTimerMessage(message);
} else if (message instanceof DataTreeCohortActorRegistry.CohortRegistryCommand) {
store.processCohortRegistryCommand(getSender(), (DataTreeCohortActorRegistry.CohortRegistryCommand) message);
} else if (message instanceof PersistAbortTransactionPayload) {
final TransactionIdentifier txId = ((PersistAbortTransactionPayload) message).getTransactionId();
persistPayload(txId, AbortTransactionPayload.create(txId), true);
} else if (message instanceof MakeLeaderLocal) {
onMakeLeaderLocal();
} else if (RESUME_NEXT_PENDING_TRANSACTION.equals(message)) {
store.resumeNextPendingTransaction();
} else if (!responseMessageSlicer.handleMessage(message)) {
super.handleNonRaftCommand(message);
}
}
}
use of org.opendaylight.controller.cluster.access.concepts.RequestEnvelope in project controller by opendaylight.
the class ConnectingClientConnectionTest method assertRequestEquals.
private static void assertRequestEquals(final Request<?, ?> expected, final long sequence, final Object obj) {
assertTrue(obj instanceof RequestEnvelope);
final RequestEnvelope actual = (RequestEnvelope) obj;
assertEquals(0, actual.getSessionId());
assertEquals(sequence, actual.getTxSequence());
assertSame(expected, actual.getMessage());
}
use of org.opendaylight.controller.cluster.access.concepts.RequestEnvelope in project controller by opendaylight.
the class TransmittingTransmitQueueTest method testRequestSlicingOnTransmit.
@Test
public void testRequestSlicingOnTransmit() throws Exception {
doReturn(true).when(mockMessageSlicer).slice(any());
ModifyTransactionRequestBuilder reqBuilder = new ModifyTransactionRequestBuilder(TRANSACTION_IDENTIFIER, probe.ref());
reqBuilder.setSequence(0L);
final Request<?, ?> request = reqBuilder.build();
final long now = now();
final Consumer<Response<?, ?>> mockConsumer = createConsumerMock();
Optional<TransmittedConnectionEntry> transmitted = queue.transmit(new ConnectionEntry(request, mockConsumer, now), now);
assertTrue(transmitted.isPresent());
ArgumentCaptor<SliceOptions> sliceOptions = ArgumentCaptor.forClass(SliceOptions.class);
verify(mockMessageSlicer).slice(sliceOptions.capture());
assertTrue(sliceOptions.getValue().getMessage() instanceof RequestEnvelope);
RequestEnvelope requestEnvelope = (RequestEnvelope) sliceOptions.getValue().getMessage();
assertEquals(request, requestEnvelope.getMessage());
final Request<?, ?> request2 = new TransactionPurgeRequest(TRANSACTION_IDENTIFIER, 1L, probe.ref());
transmitted = queue.transmit(new ConnectionEntry(request2, mockConsumer, now), now);
assertFalse(transmitted.isPresent());
}
Aggregations