Search in sources :

Example 1 with Identifier

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

the class ShardTest method testAbortWithCommitPending.

@Test
public void testAbortWithCommitPending() throws Exception {
    new ShardTestKit(getSystem()) {

        {
            final Creator<Shard> creator = () -> new Shard(newShardBuilder()) {

                @Override
                void persistPayload(final Identifier id, final Payload payload, final boolean batchHint) {
                    // Simulate an AbortTransaction message occurring during
                    // replication, after
                    // persisting and before finishing the commit to the
                    // in-memory store.
                    doAbortTransaction(id, null);
                    super.persistPayload(id, payload, batchHint);
                }
            };
            final TestActorRef<Shard> shard = actorFactory.createTestActor(Props.create(new DelegatingShardCreator(creator)).withDispatcher(Dispatchers.DefaultDispatcherId()), "testAbortWithCommitPending");
            waitUntilLeader(shard);
            final FiniteDuration duration = duration("5 seconds");
            final TransactionIdentifier transactionID = nextTransactionId();
            shard.tell(prepareBatchedModifications(transactionID, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME), false), getRef());
            expectMsgClass(duration, ReadyTransactionReply.class);
            shard.tell(new CanCommitTransaction(transactionID, CURRENT_VERSION).toSerializable(), getRef());
            expectMsgClass(duration, CanCommitTransactionReply.class);
            shard.tell(new CommitTransaction(transactionID, CURRENT_VERSION).toSerializable(), getRef());
            expectMsgClass(duration, CommitTransactionReply.class);
            final NormalizedNode<?, ?> node = readStore(shard, TestModel.TEST_PATH);
            // Since we're simulating an abort occurring during replication
            // and before finish commit,
            // the data should still get written to the in-memory store
            // since we've gotten past
            // canCommit and preCommit and persisted the data.
            assertNotNull(TestModel.TEST_QNAME.getLocalName() + " not found", node);
        }
    };
}
Also used : CanCommitTransaction(org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction) CommitTransaction(org.opendaylight.controller.cluster.datastore.messages.CommitTransaction) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) LocalHistoryIdentifier(org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier) ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) Identifier(org.opendaylight.yangtools.concepts.Identifier) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) CanCommitTransaction(org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction) FiniteDuration(scala.concurrent.duration.FiniteDuration) Payload(org.opendaylight.controller.cluster.raft.protobuff.client.messages.Payload) Test(org.junit.Test)

Example 2 with Identifier

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

the class LeaderTest method testHandleReplicateMessageWhenThereAreNoFollowers.

@Test
public void testHandleReplicateMessageWhenThereAreNoFollowers() throws Exception {
    logStart("testHandleReplicateMessageWhenThereAreNoFollowers");
    MockRaftActorContext actorContext = createActorContext();
    leader = new Leader(actorContext);
    actorContext.setLastApplied(0);
    long newLogIndex = actorContext.getReplicatedLog().lastIndex() + 1;
    long term = actorContext.getTermInformation().getCurrentTerm();
    ReplicatedLogEntry newEntry = new SimpleReplicatedLogEntry(newLogIndex, term, new MockRaftActorContext.MockPayload("foo"));
    actorContext.getReplicatedLog().append(newEntry);
    final Identifier id = new MockIdentifier("state-id");
    RaftActorBehavior raftBehavior = leader.handleMessage(leaderActor, new Replicate(leaderActor, id, newEntry, true));
    // State should not change
    assertTrue(raftBehavior instanceof Leader);
    assertEquals("getCommitIndex", newLogIndex, actorContext.getCommitIndex());
    // We should get 2 ApplyState messages - 1 for new log entry and 1 for the previous
    // one since lastApplied state is 0.
    List<ApplyState> applyStateList = MessageCollectorActor.getAllMatching(leaderActor, ApplyState.class);
    assertEquals("ApplyState count", newLogIndex, applyStateList.size());
    for (int i = 0; i <= newLogIndex - 1; i++) {
        ApplyState applyState = applyStateList.get(i);
        assertEquals("getIndex", i + 1, applyState.getReplicatedLogEntry().getIndex());
        assertEquals("getTerm", term, applyState.getReplicatedLogEntry().getTerm());
    }
    ApplyState last = applyStateList.get((int) newLogIndex - 1);
    assertEquals("getData", newEntry.getData(), last.getReplicatedLogEntry().getData());
    assertEquals("getIdentifier", id, last.getIdentifier());
}
Also used : MockRaftActorContext(org.opendaylight.controller.cluster.raft.MockRaftActorContext) SimpleReplicatedLogEntry(org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry) ReplicatedLogEntry(org.opendaylight.controller.cluster.raft.ReplicatedLogEntry) Identifier(org.opendaylight.yangtools.concepts.Identifier) Replicate(org.opendaylight.controller.cluster.raft.base.messages.Replicate) SimpleReplicatedLogEntry(org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry) ApplyState(org.opendaylight.controller.cluster.raft.base.messages.ApplyState) Test(org.junit.Test)

Example 3 with Identifier

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

the class RaftActorTest method testApplyState.

@Test
public void testApplyState() throws Exception {
    String persistenceId = factory.generateActorId("leader-");
    DefaultConfigParamsImpl config = new DefaultConfigParamsImpl();
    config.setHeartBeatInterval(new FiniteDuration(1, TimeUnit.DAYS));
    DataPersistenceProvider dataPersistenceProvider = mock(DataPersistenceProvider.class);
    TestActorRef<MockRaftActor> mockActorRef = factory.createTestActor(MockRaftActor.props(persistenceId, Collections.<String, String>emptyMap(), config, dataPersistenceProvider), persistenceId);
    MockRaftActor mockRaftActor = mockActorRef.underlyingActor();
    mockRaftActor.waitForInitializeBehaviorComplete();
    ReplicatedLogEntry entry = new SimpleReplicatedLogEntry(5, 1, new MockRaftActorContext.MockPayload("F"));
    final Identifier id = new MockIdentifier("apply-state");
    mockRaftActor.getRaftActorContext().getApplyStateConsumer().accept(new ApplyState(mockActorRef, id, entry));
    verify(mockRaftActor.actorDelegate).applyState(eq(mockActorRef), eq(id), anyObject());
}
Also used : FiniteDuration(scala.concurrent.duration.FiniteDuration) MockPayload(org.opendaylight.controller.cluster.raft.MockRaftActorContext.MockPayload) ByteString(com.google.protobuf.ByteString) SimpleReplicatedLogEntry(org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry) Identifier(org.opendaylight.yangtools.concepts.Identifier) SimpleReplicatedLogEntry(org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry) DataPersistenceProvider(org.opendaylight.controller.cluster.DataPersistenceProvider) ApplyState(org.opendaylight.controller.cluster.raft.base.messages.ApplyState) Test(org.junit.Test)

Example 4 with Identifier

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

the class MessageAssembler method createState.

private AssembledMessageState createState(final MessageSlice messageSlice) throws MessageSliceException {
    final Identifier identifier = messageSlice.getIdentifier();
    if (messageSlice.getSliceIndex() == SlicedMessageState.FIRST_SLICE_INDEX) {
        LOG.debug("{}: Received first slice for {} - creating AssembledMessageState", logContext, identifier);
        return new AssembledMessageState(identifier, messageSlice.getTotalSlices(), fileBackedStreamFactory, logContext);
    }
    LOG.debug("{}: AssembledMessageState not found for {} - returning failed reply", logContext, identifier);
    throw new MessageSliceException(String.format("No assembled state found for identifier %s and slice index %s", identifier, messageSlice.getSliceIndex()), true);
}
Also used : Identifier(org.opendaylight.yangtools.concepts.Identifier)

Example 5 with Identifier

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

the class MessageSlicer method slice.

/**
 * Slices a message into chunks based on the serialized size, the maximum message slice size and the given
 * options.
 *
 * @param options the SliceOptions
 * @return true if the message was sliced, false otherwise
 */
public boolean slice(final SliceOptions options) {
    final Identifier identifier = options.getIdentifier();
    final Serializable message = options.getMessage();
    final FileBackedOutputStream fileBackedStream;
    if (message != null) {
        LOG.debug("{}: slice: identifier: {}, message: {}", logContext, identifier, message);
        Preconditions.checkNotNull(fileBackedStreamFactory, "The FiledBackedStreamFactory must be set in order to call this slice method");
        // Serialize the message to a FileBackedOutputStream.
        fileBackedStream = fileBackedStreamFactory.newInstance();
        try (ObjectOutputStream out = new ObjectOutputStream(fileBackedStream)) {
            out.writeObject(message);
        } catch (IOException e) {
            LOG.debug("{}: Error serializing message for {}", logContext, identifier, e);
            fileBackedStream.cleanup();
            options.getOnFailureCallback().accept(e);
            return false;
        }
    } else {
        fileBackedStream = options.getFileBackedStream();
    }
    return initializeSlicing(options, fileBackedStream);
}
Also used : Serializable(java.io.Serializable) Identifier(org.opendaylight.yangtools.concepts.Identifier) FileBackedOutputStream(org.opendaylight.controller.cluster.io.FileBackedOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream)

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