use of com.google.common.primitives.UnsignedLong in project controller by opendaylight.
the class FrontendHistoryMetadata method readFrom.
public static FrontendHistoryMetadata readFrom(final DataInput in) throws IOException {
byte header = WritableObjects.readLongHeader(in);
final long historyId = WritableObjects.readFirstLong(in, header);
final long cookie = WritableObjects.readSecondLong(in, header);
final boolean closed = in.readBoolean();
header = WritableObjects.readLongHeader(in);
long ls = WritableObjects.readFirstLong(in, header);
Verify.verify(ls >= 0 && ls <= Integer.MAX_VALUE);
final int csize = (int) ls;
ls = WritableObjects.readSecondLong(in, header);
Verify.verify(ls >= 0 && ls <= Integer.MAX_VALUE);
final int psize = (int) ls;
final Map<UnsignedLong, Boolean> closedTransactions = new HashMap<>(csize);
for (int i = 0; i < csize; ++i) {
final UnsignedLong key = UnsignedLong.fromLongBits(WritableObjects.readLong(in));
final Boolean value = Boolean.valueOf(in.readBoolean());
closedTransactions.put(key, value);
}
final RangeSet<UnsignedLong> purgedTransactions = TreeRangeSet.create();
for (int i = 0; i < psize; ++i) {
final byte h = WritableObjects.readLongHeader(in);
final UnsignedLong l = UnsignedLong.fromLongBits(WritableObjects.readFirstLong(in, h));
final UnsignedLong u = UnsignedLong.fromLongBits(WritableObjects.readSecondLong(in, h));
purgedTransactions.add(Range.closed(l, u));
}
return new FrontendHistoryMetadata(historyId, cookie, closed, closedTransactions, purgedTransactions);
}
use of com.google.common.primitives.UnsignedLong in project controller by opendaylight.
the class ShardDataTreeTest method testPipelinedTransactionsWithCoordinatedCommits.
@Test
public void testPipelinedTransactionsWithCoordinatedCommits() throws Exception {
final ShardDataTreeCohort cohort1 = newShardDataTreeCohort(snapshot -> snapshot.write(CarsModel.BASE_PATH, CarsModel.emptyContainer()));
final ShardDataTreeCohort cohort2 = newShardDataTreeCohort(snapshot -> snapshot.write(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode()));
NormalizedNode<?, ?> peopleNode = PeopleModel.create();
final ShardDataTreeCohort cohort3 = newShardDataTreeCohort(snapshot -> snapshot.write(PeopleModel.BASE_PATH, peopleNode));
YangInstanceIdentifier carPath = CarsModel.newCarPath("optima");
MapEntryNode carNode = CarsModel.newCarEntry("optima", new BigInteger("100"));
final ShardDataTreeCohort cohort4 = newShardDataTreeCohort(snapshot -> snapshot.write(carPath, carNode));
immediateCanCommit(cohort1);
final FutureCallback<Void> canCommitCallback2 = coordinatedCanCommit(cohort2);
final FutureCallback<Void> canCommitCallback3 = coordinatedCanCommit(cohort3);
final FutureCallback<Void> canCommitCallback4 = coordinatedCanCommit(cohort4);
final FutureCallback<DataTreeCandidate> preCommitCallback1 = coordinatedPreCommit(cohort1);
verify(preCommitCallback1).onSuccess(cohort1.getCandidate());
verify(canCommitCallback2).onSuccess(null);
final FutureCallback<DataTreeCandidate> preCommitCallback2 = coordinatedPreCommit(cohort2);
verify(preCommitCallback2).onSuccess(cohort2.getCandidate());
verify(canCommitCallback3).onSuccess(null);
final FutureCallback<DataTreeCandidate> preCommitCallback3 = coordinatedPreCommit(cohort3);
verify(preCommitCallback3).onSuccess(cohort3.getCandidate());
verify(canCommitCallback4).onSuccess(null);
final FutureCallback<DataTreeCandidate> preCommitCallback4 = coordinatedPreCommit(cohort4);
verify(preCommitCallback4).onSuccess(cohort4.getCandidate());
final FutureCallback<UnsignedLong> commitCallback2 = coordinatedCommit(cohort2);
verify(mockShard, never()).persistPayload(eq(cohort1.getIdentifier()), any(CommitTransactionPayload.class), anyBoolean());
verifyNoMoreInteractions(commitCallback2);
final FutureCallback<UnsignedLong> commitCallback4 = coordinatedCommit(cohort4);
verify(mockShard, never()).persistPayload(eq(cohort4.getIdentifier()), any(CommitTransactionPayload.class), anyBoolean());
verifyNoMoreInteractions(commitCallback4);
final FutureCallback<UnsignedLong> commitCallback1 = coordinatedCommit(cohort1);
InOrder inOrder = inOrder(mockShard);
inOrder.verify(mockShard).persistPayload(eq(cohort1.getIdentifier()), any(CommitTransactionPayload.class), eq(true));
inOrder.verify(mockShard).persistPayload(eq(cohort2.getIdentifier()), any(CommitTransactionPayload.class), eq(false));
verifyNoMoreInteractions(commitCallback1);
verifyNoMoreInteractions(commitCallback2);
final FutureCallback<UnsignedLong> commitCallback3 = coordinatedCommit(cohort3);
inOrder = inOrder(mockShard);
inOrder.verify(mockShard).persistPayload(eq(cohort3.getIdentifier()), any(CommitTransactionPayload.class), eq(true));
inOrder.verify(mockShard).persistPayload(eq(cohort4.getIdentifier()), any(CommitTransactionPayload.class), eq(false));
verifyNoMoreInteractions(commitCallback3);
verifyNoMoreInteractions(commitCallback4);
final ShardDataTreeCohort cohort5 = newShardDataTreeCohort(snapshot -> snapshot.merge(CarsModel.BASE_PATH, CarsModel.emptyContainer()));
final FutureCallback<Void> canCommitCallback5 = coordinatedCanCommit(cohort5);
// The payload instance doesn't matter - it just needs to be of type CommitTransactionPayload.
CommitTransactionPayload mockPayload = CommitTransactionPayload.create(nextTransactionId(), cohort1.getCandidate());
shardDataTree.applyReplicatedPayload(cohort1.getIdentifier(), mockPayload);
shardDataTree.applyReplicatedPayload(cohort2.getIdentifier(), mockPayload);
shardDataTree.applyReplicatedPayload(cohort3.getIdentifier(), mockPayload);
shardDataTree.applyReplicatedPayload(cohort4.getIdentifier(), mockPayload);
inOrder = inOrder(commitCallback1, commitCallback2, commitCallback3, commitCallback4);
inOrder.verify(commitCallback1).onSuccess(any(UnsignedLong.class));
inOrder.verify(commitCallback2).onSuccess(any(UnsignedLong.class));
inOrder.verify(commitCallback3).onSuccess(any(UnsignedLong.class));
inOrder.verify(commitCallback4).onSuccess(any(UnsignedLong.class));
verify(canCommitCallback5).onSuccess(null);
final DataTreeSnapshot snapshot = shardDataTree.newReadOnlyTransaction(nextTransactionId()).getSnapshot();
Optional<NormalizedNode<?, ?>> optional = snapshot.readNode(carPath);
assertEquals("Car node present", true, optional.isPresent());
assertEquals("Car node", carNode, optional.get());
optional = snapshot.readNode(PeopleModel.BASE_PATH);
assertEquals("People node present", true, optional.isPresent());
assertEquals("People node", peopleNode, optional.get());
}
use of com.google.common.primitives.UnsignedLong in project controller by opendaylight.
the class ShardDataTreeTest method testPipelinedTransactionsWithImmediateReplication.
@Test
public void testPipelinedTransactionsWithImmediateReplication() throws Exception {
immediatePayloadReplication(shardDataTree, mockShard);
final ShardDataTreeCohort cohort1 = newShardDataTreeCohort(snapshot -> snapshot.write(CarsModel.BASE_PATH, CarsModel.emptyContainer()));
final ShardDataTreeCohort cohort2 = newShardDataTreeCohort(snapshot -> snapshot.write(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode()));
YangInstanceIdentifier carPath = CarsModel.newCarPath("optima");
MapEntryNode carNode = CarsModel.newCarEntry("optima", new BigInteger("100"));
final ShardDataTreeCohort cohort3 = newShardDataTreeCohort(snapshot -> snapshot.write(carPath, carNode));
final FutureCallback<UnsignedLong> commitCallback1 = immediate3PhaseCommit(cohort1);
final FutureCallback<UnsignedLong> commitCallback2 = immediate3PhaseCommit(cohort2);
final FutureCallback<UnsignedLong> commitCallback3 = immediate3PhaseCommit(cohort3);
InOrder inOrder = inOrder(commitCallback1, commitCallback2, commitCallback3);
inOrder.verify(commitCallback1).onSuccess(any(UnsignedLong.class));
inOrder.verify(commitCallback2).onSuccess(any(UnsignedLong.class));
inOrder.verify(commitCallback3).onSuccess(any(UnsignedLong.class));
final DataTreeSnapshot snapshot = shardDataTree.newReadOnlyTransaction(nextTransactionId()).getSnapshot();
Optional<NormalizedNode<?, ?>> optional = snapshot.readNode(CarsModel.BASE_PATH);
assertEquals("Car node present", true, optional.isPresent());
}
use of com.google.common.primitives.UnsignedLong in project controller by opendaylight.
the class ShardDataTreeTest method testPipelinedTransactionsWithImmediateCommits.
@Test
public void testPipelinedTransactionsWithImmediateCommits() throws Exception {
final ShardDataTreeCohort cohort1 = newShardDataTreeCohort(snapshot -> snapshot.write(CarsModel.BASE_PATH, CarsModel.emptyContainer()));
final ShardDataTreeCohort cohort2 = newShardDataTreeCohort(snapshot -> snapshot.write(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode()));
YangInstanceIdentifier carPath = CarsModel.newCarPath("optima");
MapEntryNode carNode = CarsModel.newCarEntry("optima", new BigInteger("100"));
final ShardDataTreeCohort cohort3 = newShardDataTreeCohort(snapshot -> snapshot.write(carPath, carNode));
final FutureCallback<UnsignedLong> commitCallback2 = immediate3PhaseCommit(cohort2);
final FutureCallback<UnsignedLong> commitCallback3 = immediate3PhaseCommit(cohort3);
final FutureCallback<UnsignedLong> commitCallback1 = immediate3PhaseCommit(cohort1);
InOrder inOrder = inOrder(mockShard);
inOrder.verify(mockShard).persistPayload(eq(cohort1.getIdentifier()), any(CommitTransactionPayload.class), eq(true));
inOrder.verify(mockShard).persistPayload(eq(cohort2.getIdentifier()), any(CommitTransactionPayload.class), eq(true));
inOrder.verify(mockShard).persistPayload(eq(cohort3.getIdentifier()), any(CommitTransactionPayload.class), eq(false));
// The payload instance doesn't matter - it just needs to be of type CommitTransactionPayload.
CommitTransactionPayload mockPayload = CommitTransactionPayload.create(nextTransactionId(), cohort1.getCandidate());
shardDataTree.applyReplicatedPayload(cohort1.getIdentifier(), mockPayload);
shardDataTree.applyReplicatedPayload(cohort2.getIdentifier(), mockPayload);
shardDataTree.applyReplicatedPayload(cohort3.getIdentifier(), mockPayload);
inOrder = inOrder(commitCallback1, commitCallback2, commitCallback3);
inOrder.verify(commitCallback1).onSuccess(any(UnsignedLong.class));
inOrder.verify(commitCallback2).onSuccess(any(UnsignedLong.class));
inOrder.verify(commitCallback3).onSuccess(any(UnsignedLong.class));
final DataTreeSnapshot snapshot = shardDataTree.newReadOnlyTransaction(nextTransactionId()).getSnapshot();
Optional<NormalizedNode<?, ?>> optional = snapshot.readNode(carPath);
assertEquals("Car node present", true, optional.isPresent());
assertEquals("Car node", carNode, optional.get());
}
use of com.google.common.primitives.UnsignedLong in project controller by opendaylight.
the class SimpleShardDataTreeCohortTest method testCommitWithIllegalArgumentEx.
@Test
public void testCommitWithIllegalArgumentEx() {
canCommitSuccess();
final DataTreeCandidateTip candidate = preCommitSuccess();
final Exception cause = new IllegalArgumentException("mock");
doAnswer(invocation -> {
invocation.getArgumentAt(0, SimpleShardDataTreeCohort.class).failedCommit(cause);
return null;
}).when(mockShardDataTree).startCommit(cohort, candidate);
@SuppressWarnings("unchecked") final FutureCallback<UnsignedLong> callback = mock(FutureCallback.class);
cohort.commit(callback);
verify(callback).onFailure(cause);
verifyNoMoreInteractions(callback);
verify(mockUserCohorts).abort();
}
Aggregations