use of org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException in project controller by opendaylight.
the class ActorContextTest method testBroadcast.
@Test
public void testBroadcast() {
new TestKit(getSystem()) {
{
ActorRef shardActorRef1 = getSystem().actorOf(MessageCollectorActor.props());
ActorRef shardActorRef2 = getSystem().actorOf(MessageCollectorActor.props());
TestActorRef<MockShardManager> shardManagerActorRef = TestActorRef.create(getSystem(), MockShardManager.props());
MockShardManager shardManagerActor = shardManagerActorRef.underlyingActor();
shardManagerActor.addFindPrimaryResp("shard1", new RemotePrimaryShardFound(shardActorRef1.path().toString(), DataStoreVersions.CURRENT_VERSION));
shardManagerActor.addFindPrimaryResp("shard2", new RemotePrimaryShardFound(shardActorRef2.path().toString(), DataStoreVersions.CURRENT_VERSION));
shardManagerActor.addFindPrimaryResp("shard3", new NoShardLeaderException("not found"));
Configuration mockConfig = mock(Configuration.class);
doReturn(Sets.newLinkedHashSet(Arrays.asList("shard1", "shard2", "shard3"))).when(mockConfig).getAllShardNames();
ActorContext actorContext = new ActorContext(getSystem(), shardManagerActorRef, mock(ClusterWrapper.class), mockConfig, DatastoreContext.newBuilder().shardInitializationTimeout(200, TimeUnit.MILLISECONDS).build(), new PrimaryShardInfoFutureCache());
actorContext.broadcast(v -> new TestMessage(), TestMessage.class);
MessageCollectorActor.expectFirstMatching(shardActorRef1, TestMessage.class);
MessageCollectorActor.expectFirstMatching(shardActorRef2, TestMessage.class);
}
};
}
use of org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException in project controller by opendaylight.
the class RemoteTransactionContextSupport method createTransactionContext.
private void createTransactionContext(final Throwable failure, final Object response) {
// Create the TransactionContext from the response or failure. Store the new
// TransactionContext locally until we've completed invoking the
// TransactionOperations. This avoids thread timing issues which could cause
// out-of-order TransactionOperations. Eg, on a modification operation, if the
// TransactionContext is non-null, then we directly call the TransactionContext.
// However, at the same time, the code may be executing the cached
// TransactionOperations. So to avoid thus timing, we don't publish the
// TransactionContext until after we've executed all cached TransactionOperations.
TransactionContext localTransactionContext;
if (failure != null) {
LOG.debug("Tx {} Creating NoOpTransaction because of error", getIdentifier(), failure);
Throwable resultingEx = failure;
if (failure instanceof AskTimeoutException) {
resultingEx = new ShardLeaderNotRespondingException(String.format("Could not create a %s transaction on shard %s. The shard leader isn't responding.", parent.getType(), shardName), failure);
} else if (!(failure instanceof NoShardLeaderException)) {
resultingEx = new Exception(String.format("Error creating %s transaction on shard %s", parent.getType(), shardName), failure);
}
localTransactionContext = new NoOpTransactionContext(resultingEx, getIdentifier());
} else if (CreateTransactionReply.isSerializedType(response)) {
localTransactionContext = createValidTransactionContext(CreateTransactionReply.fromSerializable(response));
} else {
IllegalArgumentException exception = new IllegalArgumentException(String.format("Invalid reply type %s for CreateTransaction", response.getClass()));
localTransactionContext = new NoOpTransactionContext(exception, getIdentifier());
}
transactionContextWrapper.executePriorTransactionOperations(localTransactionContext);
}
use of org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException in project controller by opendaylight.
the class NoOpTransactionContext method executeRead.
@Override
public <T> void executeRead(AbstractRead<T> readCmd, SettableFuture<T> proxyFuture) {
LOG.debug("Tx {} executeRead {} called path = {}", getIdentifier(), readCmd.getClass().getSimpleName(), readCmd.getPath());
final Throwable t;
if (failure instanceof NoShardLeaderException) {
t = new DataStoreUnavailableException(failure.getMessage(), failure);
} else {
t = failure;
}
proxyFuture.setException(new ReadFailedException("Error executeRead " + readCmd.getClass().getSimpleName() + " for path " + readCmd.getPath(), t));
}
use of org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException in project controller by opendaylight.
the class ShardManagerTest method testChangeServersVotingStatusWithNoLeader.
@Test
public void testChangeServersVotingStatusWithNoLeader() throws Exception {
new TestKit(getSystem()) {
{
String memberId = "member-1-shard-default-" + shardMrgIDSuffix;
ActorRef respondActor = actorFactory.createActor(Props.create(MockRespondActor.class, ChangeServersVotingStatus.class, new ServerChangeReply(ServerChangeStatus.NO_LEADER, null)), memberId);
ActorRef shardManager = getSystem().actorOf(newPropsShardMgrWithMockShardActor(respondActor));
shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
shardManager.tell(new ActorInitialized(), respondActor);
shardManager.tell(new RoleChangeNotification(memberId, null, RaftState.Follower.name()), respondActor);
shardManager.tell(new ChangeShardMembersVotingStatus("default", ImmutableMap.of("member-2", Boolean.TRUE)), getRef());
MessageCollectorActor.expectFirstMatching(respondActor, ChangeServersVotingStatus.class);
Status.Failure resp = expectMsgClass(duration("5 seconds"), Status.Failure.class);
assertEquals("Failure resposnse", true, resp.cause() instanceof NoShardLeaderException);
}
};
}
use of org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException in project controller by opendaylight.
the class ConcurrentDOMDataBrokerTest method testSubmitWithCanCommitDataStoreUnavailableException.
@Test
public void testSubmitWithCanCommitDataStoreUnavailableException() throws Exception {
doReturn(Futures.immediateFuture(true)).when(mockCohort1).canCommit();
doReturn(Futures.immediateFuture(null)).when(mockCohort1).abort();
NoShardLeaderException rootCause = new NoShardLeaderException("mock");
DataStoreUnavailableException cause = new DataStoreUnavailableException(rootCause.getMessage(), rootCause);
doReturn(Futures.immediateFailedFuture(rootCause)).when(mockCohort2).canCommit();
doReturn(Futures.immediateFuture(null)).when(mockCohort2).abort();
CheckedFuture<Void, TransactionCommitFailedException> future = coordinator.submit(transaction, Arrays.asList(mockCohort1, mockCohort2));
assertFailure(future, cause, mockCohort1, mockCohort2);
}
Aggregations