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);
}
};
}
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());
}
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());
}
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);
}
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);
}
Aggregations