Search in sources :

Example 11 with Identifier

use of org.opendaylight.yangtools.concepts.Identifier in project controller by opendaylight.

the class MessageSlicer method initializeSlicing.

private boolean initializeSlicing(final SliceOptions options, final FileBackedOutputStream fileBackedStream) {
    final Identifier identifier = options.getIdentifier();
    MessageSliceIdentifier messageSliceId = new MessageSliceIdentifier(identifier, id);
    SlicedMessageState<ActorRef> state = null;
    try {
        state = new SlicedMessageState<>(messageSliceId, fileBackedStream, messageSliceSize, maxSlicingTries, options.getReplyTo(), options.getOnFailureCallback(), logContext);
        final Serializable message = options.getMessage();
        if (state.getTotalSlices() == 1 && message != null) {
            LOG.debug("{}: Message does not need to be sliced - sending original message", logContext);
            state.close();
            sendTo(options, message, options.getReplyTo());
            return false;
        }
        final MessageSlice firstSlice = getNextSliceMessage(state);
        LOG.debug("{}: Sending first slice: {}", logContext, firstSlice);
        stateCache.put(messageSliceId, state);
        sendTo(options, firstSlice, ActorRef.noSender());
        return true;
    } catch (IOException e) {
        LOG.error("{}: Error initializing SlicedMessageState for {}", logContext, identifier, e);
        if (state != null) {
            state.close();
        } else {
            fileBackedStream.cleanup();
        }
        options.getOnFailureCallback().accept(e);
        return false;
    }
}
Also used : Serializable(java.io.Serializable) Identifier(org.opendaylight.yangtools.concepts.Identifier) ActorRef(akka.actor.ActorRef) IOException(java.io.IOException)

Example 12 with Identifier

use of org.opendaylight.yangtools.concepts.Identifier in project controller by opendaylight.

the class MessageSlicingIntegrationTest method testSlicing.

@SuppressWarnings("unchecked")
private void testSlicing(final String logContext, final int messageSliceSize, final int expTotalSlices, final byte[] messageData) {
    reset(mockAssembledMessageCallback);
    final BytesMessage message = new BytesMessage(messageData);
    try (MessageSlicer slicer = newMessageSlicer(logContext, messageSliceSize)) {
        final boolean wasSliced = slice(slicer, IDENTIFIER, message, sendToProbe.ref(), replyToProbe.ref(), mockOnFailureCallback);
        assertTrue(wasSliced);
        Identifier slicingId = null;
        int expLastSliceHashCode = SlicedMessageState.INITIAL_SLICE_HASH_CODE;
        for (int sliceIndex = 1; sliceIndex <= expTotalSlices; sliceIndex++) {
            final MessageSlice sliceMessage = sendToProbe.expectMsgClass(MessageSlice.class);
            slicingId = sliceMessage.getIdentifier();
            assertMessageSlice(sliceMessage, IDENTIFIER, sliceIndex, expTotalSlices, expLastSliceHashCode, replyToProbe.ref());
            assembler.handleMessage(sliceMessage, sendToProbe.ref());
            final MessageSliceReply reply = replyToProbe.expectMsgClass(MessageSliceReply.class);
            assertSuccessfulMessageSliceReply(reply, IDENTIFIER, sliceIndex);
            expLastSliceHashCode = Arrays.hashCode(sliceMessage.getData());
            slicer.handleMessage(reply);
        }
        assertAssembledMessage(message, replyToProbe.ref());
        assertFalse("MessageSlicer did not remove state for " + slicingId, slicer.hasState(slicingId));
        assertFalse("MessageAssembler did not remove state for " + slicingId, assembler.hasState(slicingId));
    }
}
Also used : Identifier(org.opendaylight.yangtools.concepts.Identifier)

Example 13 with Identifier

use of org.opendaylight.yangtools.concepts.Identifier in project controller by opendaylight.

the class MessageSlicingIntegrationTest method testSlicingWithMaxRetriesReached.

@Test
public void testSlicingWithMaxRetriesReached() {
    LOG.info("testSlicingWithMaxRetriesReached starting");
    final BytesMessage message = new BytesMessage(new byte[] { 1, 2, 3 });
    final int messageSliceSize = SerializationUtils.serialize(message).length / 2;
    try (MessageSlicer slicer = newMessageSlicer("testSlicingWithMaxRetriesReached", messageSliceSize)) {
        slice(slicer, IDENTIFIER, message, sendToProbe.ref(), replyToProbe.ref(), mockOnFailureCallback);
        Identifier slicingId = null;
        for (int i = 0; i < MessageSlicer.DEFAULT_MAX_SLICING_TRIES; i++) {
            MessageSlice sliceMessage = sendToProbe.expectMsgClass(MessageSlice.class);
            slicingId = sliceMessage.getIdentifier();
            assertMessageSlice(sliceMessage, IDENTIFIER, 1, DONT_CARE, SlicedMessageState.INITIAL_SLICE_HASH_CODE, replyToProbe.ref());
            assembler.handleMessage(sliceMessage, sendToProbe.ref());
            // Swallow the reply and send the MessageSlicer a reply with an invalid index.
            final MessageSliceReply reply = replyToProbe.expectMsgClass(MessageSliceReply.class);
            assertSuccessfulMessageSliceReply(reply, IDENTIFIER, sliceMessage.getSliceIndex());
            slicer.handleMessage(MessageSliceReply.success(reply.getIdentifier(), 100000, reply.getSendTo()));
            final AbortSlicing abortSlicing = sendToProbe.expectMsgClass(AbortSlicing.class);
            assertEquals("Identifier", slicingId, abortSlicing.getIdentifier());
            assembler.handleMessage(abortSlicing, sendToProbe.ref());
        }
        slicer.handleMessage(MessageSliceReply.success(slicingId, 100000, sendToProbe.ref()));
        assertFailureCallback(RuntimeException.class);
        assertFalse("MessageSlicer did not remove state for " + slicingId, slicer.hasState(slicingId));
        assertFalse("MessageAssembler did not remove state for " + slicingId, assembler.hasState(slicingId));
    }
    LOG.info("testSlicingWithMaxRetriesReached ending");
}
Also used : Identifier(org.opendaylight.yangtools.concepts.Identifier) Test(org.junit.Test)

Aggregations

Identifier (org.opendaylight.yangtools.concepts.Identifier)13 Test (org.junit.Test)5 ActorRef (akka.actor.ActorRef)3 IOException (java.io.IOException)3 SimpleReplicatedLogEntry (org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry)3 FiniteDuration (scala.concurrent.duration.FiniteDuration)3 Serializable (java.io.Serializable)2 MockRaftActorContext (org.opendaylight.controller.cluster.raft.MockRaftActorContext)2 ApplyState (org.opendaylight.controller.cluster.raft.base.messages.ApplyState)2 ByteString (com.google.protobuf.ByteString)1 ObjectOutputStream (java.io.ObjectOutputStream)1 ExecutionException (java.util.concurrent.ExecutionException)1 DataPersistenceProvider (org.opendaylight.controller.cluster.DataPersistenceProvider)1 LocalHistoryIdentifier (org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier)1 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)1 ShardIdentifier (org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier)1 CanCommitTransaction (org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction)1 CommitTransaction (org.opendaylight.controller.cluster.datastore.messages.CommitTransaction)1 FileBackedOutputStream (org.opendaylight.controller.cluster.io.FileBackedOutputStream)1 MessageSlice (org.opendaylight.controller.cluster.messaging.MessageSlice)1