use of io.pravega.client.control.impl.ControllerFailureException in project pravega by pravega.
the class LocalControllerTest method testUpdateReaderGroup.
@Test(timeout = 10000)
public void testUpdateReaderGroup() throws ExecutionException, InterruptedException {
final Segment seg0 = new Segment("scope", "stream1", 0L);
final Segment seg1 = new Segment("scope", "stream1", 1L);
ImmutableMap<Segment, Long> startStreamCut = ImmutableMap.of(seg0, 10L, seg1, 10L);
Map<Stream, StreamCut> startSC = ImmutableMap.of(Stream.of("scope", "stream1"), new StreamCutImpl(Stream.of("scope", "stream1"), startStreamCut));
ImmutableMap<Segment, Long> endStreamCut = ImmutableMap.of(seg0, 200L, seg1, 300L);
Map<Stream, StreamCut> endSC = ImmutableMap.of(Stream.of("scope", "stream1"), new StreamCutImpl(Stream.of("scope", "stream1"), endStreamCut));
ReaderGroupConfig rgConfig = ReaderGroupConfig.builder().automaticCheckpointIntervalMillis(30000L).groupRefreshTimeMillis(20000L).maxOutstandingCheckpointRequest(2).retentionType(ReaderGroupConfig.StreamDataRetention.AUTOMATIC_RELEASE_AT_LAST_CHECKPOINT).startingStreamCuts(startSC).endingStreamCuts(endSC).build();
ReaderGroupConfig config = ReaderGroupConfig.cloneConfig(rgConfig, UUID.randomUUID(), 0L);
when(this.mockControllerService.updateReaderGroup(anyString(), anyString(), any(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.UpdateReaderGroupResponse.newBuilder().setStatus(Controller.UpdateReaderGroupResponse.Status.SUCCESS).setGeneration(1L).build()));
Assert.assertNotNull(this.testController.updateReaderGroup("scope", "subscriber", config).join());
when(this.mockControllerService.updateReaderGroup(anyString(), anyString(), any(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.UpdateReaderGroupResponse.newBuilder().setStatus(Controller.UpdateReaderGroupResponse.Status.FAILURE).build()));
assertThrows("Expected ControllerFailureException", () -> this.testController.updateReaderGroup("scope", "subscriber", config).join(), ex -> ex instanceof ControllerFailureException);
when(this.mockControllerService.updateReaderGroup(anyString(), anyString(), any(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.UpdateReaderGroupResponse.newBuilder().setStatus(Controller.UpdateReaderGroupResponse.Status.INVALID_CONFIG).build()));
assertThrows("Expected ReaderGroupConfigRejectedException", () -> this.testController.updateReaderGroup("scope", "subscriber", config).join(), ex -> ex instanceof ReaderGroupConfigRejectedException);
when(this.mockControllerService.updateReaderGroup(anyString(), anyString(), any(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.UpdateReaderGroupResponse.newBuilder().setStatus(Controller.UpdateReaderGroupResponse.Status.RG_NOT_FOUND).build()));
assertThrows("Expected IllegalArgumentException", () -> this.testController.updateReaderGroup("scope", "subscriber", config).join(), ex -> ex instanceof IllegalArgumentException);
when(this.mockControllerService.updateReaderGroup(anyString(), anyString(), any(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.UpdateReaderGroupResponse.newBuilder().setStatusValue(-1).build()));
assertThrows("Expected ControllerFailureException", () -> this.testController.updateReaderGroup("scope", "subscriber", config).join(), ex -> ex instanceof ControllerFailureException);
}
use of io.pravega.client.control.impl.ControllerFailureException in project pravega by pravega.
the class LocalControllerTest method testGetKeyValueTableConfiguration.
@Test(timeout = 10000)
public void testGetKeyValueTableConfiguration() {
KeyValueTableConfiguration config = KeyValueTableConfiguration.builder().partitionCount(2).primaryKeyLength(4).secondaryKeyLength(4).build();
when(this.mockControllerService.getKeyValueTableConfiguration(any(), any(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.KeyValueTableConfigResponse.newBuilder().setStatus(Controller.KeyValueTableConfigResponse.Status.SUCCESS).setConfig(ModelHelper.decode("scope", "kvtable1", config)).build()));
KeyValueTableConfiguration responseConfig = this.testController.getKeyValueTableConfiguration("scope", "kvtable1").join();
assertEquals(config.getPartitionCount(), responseConfig.getPartitionCount());
assertEquals(config.getPrimaryKeyLength(), responseConfig.getPrimaryKeyLength());
assertEquals(config.getSecondaryKeyLength(), responseConfig.getSecondaryKeyLength());
when(this.mockControllerService.getKeyValueTableConfiguration(any(), any(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.KeyValueTableConfigResponse.newBuilder().setStatus(Controller.KeyValueTableConfigResponse.Status.FAILURE).build()));
assertThrows("Expected ControllerFailureException", () -> this.testController.getKeyValueTableConfiguration("scope", "kvtable2").join(), ex -> ex instanceof ControllerFailureException);
when(this.mockControllerService.getKeyValueTableConfiguration(any(), any(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.KeyValueTableConfigResponse.newBuilder().setStatus(Controller.KeyValueTableConfigResponse.Status.TABLE_NOT_FOUND).build()));
assertThrows("Expected IllegalArgumentException", () -> this.testController.getKeyValueTableConfiguration("scope", "kvtable3").join(), ex -> ex instanceof IllegalArgumentException);
when(this.mockControllerService.getKeyValueTableConfiguration(any(), any(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.KeyValueTableConfigResponse.newBuilder().setStatusValue(-1).build()));
assertThrows("Expected ControllerFailureException", () -> this.testController.getKeyValueTableConfiguration("scope", "kvtable4").join(), ex -> ex instanceof ControllerFailureException);
}
use of io.pravega.client.control.impl.ControllerFailureException in project pravega by pravega.
the class LocalControllerTest method testScaleStream.
@Test(timeout = 10000)
public void testScaleStream() throws ExecutionException, InterruptedException {
when(this.mockControllerService.checkScale(anyString(), anyString(), anyInt(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.ScaleStatusResponse.newBuilder().setStatus(Controller.ScaleStatusResponse.ScaleStatus.SUCCESS).build()));
when(this.mockControllerService.scale(any(), any(), any(), any(), anyLong(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.ScaleResponse.newBuilder().setStatus(Controller.ScaleResponse.ScaleStreamStatus.STARTED).build()));
Assert.assertTrue(this.testController.scaleStream(new StreamImpl("scope", "stream"), new ArrayList<>(), new HashMap<>(), executorService()).getFuture().join());
when(this.mockControllerService.scale(any(), any(), any(), any(), anyLong(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.ScaleResponse.newBuilder().setStatus(Controller.ScaleResponse.ScaleStreamStatus.PRECONDITION_FAILED).build()));
Assert.assertFalse(this.testController.scaleStream(new StreamImpl("scope", "stream"), new ArrayList<>(), new HashMap<>(), executorService()).getFuture().join());
when(this.mockControllerService.scale(any(), any(), any(), any(), anyLong(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.ScaleResponse.newBuilder().setStatus(Controller.ScaleResponse.ScaleStreamStatus.FAILURE).build()));
assertThrows("Expected ControllerFailureException", () -> this.testController.startScale(new StreamImpl("scope", "stream"), new ArrayList<>(), new HashMap<>()).join(), ex -> ex instanceof ControllerFailureException);
when(this.mockControllerService.scale(any(), any(), any(), any(), anyLong(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.ScaleResponse.newBuilder().setStatusValue(-1).build()));
assertThrows("Expected ControllerFailureException", () -> this.testController.startScale(new StreamImpl("scope", "stream"), new ArrayList<>(), new HashMap<>()).join(), ex -> ex instanceof ControllerFailureException);
}
use of io.pravega.client.control.impl.ControllerFailureException in project pravega by pravega.
the class SegmentSelector method refreshSegmentEventWritersUponSealed.
/**
* Refresh segment writers corresponding to the successors of the sealed segment and return inflight event list of the sealed segment.
* The segment writer for sealed segment is not removed.
* @param sealedSegment The sealed segment.
* @param segmentSealedCallback Sealed segment callback.
* @return List of pending events.
*/
public List<PendingEvent> refreshSegmentEventWritersUponSealed(Segment sealedSegment, Consumer<Segment> segmentSealedCallback) {
StreamSegmentsWithPredecessors successors = Futures.getAndHandleExceptions(controller.getSuccessors(sealedSegment), t -> {
log.error("Error while fetching successors for segment: {}", sealedSegment, t);
// Remove all writers and fail all pending writes
Exception e = (t instanceof RetriesExhaustedException) ? new ControllerFailureException(t) : new NoSuchSegmentException(sealedSegment.toString(), t);
removeAllWriters().forEach(event -> event.getAckFuture().completeExceptionally(e));
return null;
});
if (successors == null) {
return Collections.emptyList();
} else if (successors.getSegmentToPredecessor().isEmpty()) {
log.warn("Stream {} is sealed since no successor segments found for segment {} ", sealedSegment.getStream(), sealedSegment);
Exception e = new IllegalStateException("Writes cannot proceed since the stream is sealed");
removeAllWriters().forEach(pendingEvent -> pendingEvent.getAckFuture().completeExceptionally(e));
sealed.set(true);
return Collections.emptyList();
} else {
return updateSegmentsUponSealed(successors, sealedSegment, segmentSealedCallback);
}
}
use of io.pravega.client.control.impl.ControllerFailureException in project pravega by pravega.
the class StreamManagerImplTest method testForceDeleteScopeWithReaderGroups.
@Test
public void testForceDeleteScopeWithReaderGroups() throws ConnectionFailedException, DeleteScopeFailedException {
// Setup Mocks
ClientConnection connection = mock(ClientConnection.class);
PravegaNodeUri location = new PravegaNodeUri("localhost", 0);
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
WireCommands.CreateSegment request = (WireCommands.CreateSegment) invocation.getArgument(0);
connectionFactory.getProcessor(location).process(new WireCommands.SegmentCreated(request.getRequestId(), request.getSegment()));
return null;
}
}).when(connection).send(Mockito.any(WireCommands.CreateSegment.class));
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
WireCommands.GetStreamSegmentInfo request = (WireCommands.GetStreamSegmentInfo) invocation.getArgument(0);
connectionFactory.getProcessor(location).process(new WireCommands.StreamSegmentInfo(request.getRequestId(), request.getSegmentName(), true, false, false, 0, 0, 0));
return null;
}
}).when(connection).send(Mockito.any(WireCommands.GetStreamSegmentInfo.class));
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
WireCommands.DeleteSegment request = (WireCommands.DeleteSegment) invocation.getArgument(0);
connectionFactory.getProcessor(location).process(new WireCommands.SegmentDeleted(request.getRequestId(), request.getSegment()));
return null;
}
}).when(connection).send(Mockito.any(WireCommands.DeleteSegment.class));
connectionFactory.provideConnection(location, connection);
MockController mockController = spy(new MockController(location.getEndpoint(), location.getPort(), connectionFactory, true));
ConnectionPoolImpl pool = new ConnectionPoolImpl(ClientConfig.builder().maxConnectionsPerSegmentStore(1).build(), connectionFactory);
@Cleanup final StreamManager streamManager = new StreamManagerImpl(mockController, pool);
String scope = "scope";
String stream1 = "stream1";
String stream2 = "stream2";
String readerGroup1 = "readerGroup1";
String readerGroup2 = "readerGroup2";
ReaderGroupConfig config1 = ReaderGroupConfig.builder().stream(NameUtils.getScopedStreamName(scope, stream1)).build();
ReaderGroupConfig config2 = ReaderGroupConfig.builder().stream(NameUtils.getScopedStreamName(scope, stream2)).build();
streamManager.createScope(scope);
streamManager.createStream(scope, stream1, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(3)).build());
streamManager.createStream(scope, stream2, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(3)).build());
Set<Stream> streams = Sets.newHashSet(streamManager.listStreams(scope));
assertEquals(2, streams.size());
assertTrue(streams.stream().anyMatch(x -> x.getStreamName().equals(stream1)));
assertTrue(streams.stream().anyMatch(x -> x.getStreamName().equals(stream2)));
mockController.createReaderGroup(scope, readerGroup1, config1);
mockController.createReaderGroup(scope, readerGroup2, config2);
// mock controller client to throw exceptions when attempting to get config for reader-group.
doAnswer(x -> Futures.failedFuture(new ControllerFailureException("Unable to access reader-group config"))).when(mockController).getReaderGroupConfig(scope, readerGroup1);
doAnswer(x -> new AsyncIterator<Stream>() {
final Iterator<Stream> iterator = new ArrayList<Stream>(Arrays.asList(new StreamImpl(scope, stream1), new StreamImpl(scope, stream2), new StreamImpl(scope, NameUtils.getStreamForReaderGroup(readerGroup1)), new StreamImpl(scope, NameUtils.getStreamForReaderGroup(readerGroup2)))).iterator();
@Override
public CompletableFuture<Stream> getNext() {
Stream next;
if (!iterator.hasNext()) {
next = null;
} else {
next = iterator.next();
}
return CompletableFuture.completedFuture(next);
}
}).when(mockController).listStreams(scope);
AssertExtensions.assertThrows("Should have thrown exception", () -> streamManager.deleteScope(scope, true), e -> Exceptions.unwrap(e) instanceof DeleteScopeFailedException);
// reset mock controller
reset(mockController);
streamManager.createStream(scope, stream1, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(3)).build());
streamManager.createStream(scope, stream2, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(3)).build());
streams = Sets.newHashSet(streamManager.listStreams(scope));
assertEquals(2, streams.size());
assertTrue(streams.stream().anyMatch(x -> x.getStreamName().equals(stream1)));
assertTrue(streams.stream().anyMatch(x -> x.getStreamName().equals(stream2)));
mockController.createReaderGroup(scope, readerGroup1, config1);
mockController.createReaderGroup(scope, readerGroup2, config2);
// mock controller client to throw exceptions when attempting to delete the reader-group.
doAnswer(x -> Futures.failedFuture(new ControllerFailureException("Unable to delete reader-group"))).when(mockController).deleteReaderGroup(scope, readerGroup1, config1.getReaderGroupId());
doAnswer(x -> new AsyncIterator<Stream>() {
final Iterator<Stream> iterator = new ArrayList<Stream>(Arrays.asList(new StreamImpl(scope, stream1), new StreamImpl(scope, stream2), new StreamImpl(scope, NameUtils.getStreamForReaderGroup(readerGroup1)), new StreamImpl(scope, NameUtils.getStreamForReaderGroup(readerGroup2)))).iterator();
@Override
public CompletableFuture<Stream> getNext() {
Stream next;
if (!iterator.hasNext()) {
next = null;
} else {
next = iterator.next();
}
return CompletableFuture.completedFuture(next);
}
}).when(mockController).listStreams(scope);
AssertExtensions.assertThrows("Should have thrown exception", () -> streamManager.deleteScope(scope, true), e -> Exceptions.unwrap(e) instanceof DeleteScopeFailedException);
// reset mock controller
reset(mockController);
streamManager.createStream(scope, stream1, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(3)).build());
streamManager.createStream(scope, stream2, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(3)).build());
streams = Sets.newHashSet(streamManager.listStreams(scope));
assertEquals(2, streams.size());
assertTrue(streams.stream().anyMatch(x -> x.getStreamName().equals(stream1)));
assertTrue(streams.stream().anyMatch(x -> x.getStreamName().equals(stream2)));
mockController.createReaderGroup(scope, readerGroup1, config1);
mockController.createReaderGroup(scope, readerGroup2, config2);
// mock controller client to throw ReaderGroupNotFoundException when attempting to get the config of reader-group.
doAnswer(x -> Futures.failedFuture(new ReaderGroupNotFoundException("Reader-group does not exist"))).when(mockController).getReaderGroupConfig(scope, readerGroup1);
doAnswer(x -> new AsyncIterator<Stream>() {
final Iterator<Stream> iterator = new ArrayList<Stream>(Arrays.asList(new StreamImpl(scope, stream1), new StreamImpl(scope, stream2), new StreamImpl(scope, NameUtils.getStreamForReaderGroup(readerGroup1)), new StreamImpl(scope, NameUtils.getStreamForReaderGroup(readerGroup2)))).iterator();
@Override
public CompletableFuture<Stream> getNext() {
Stream next;
if (!iterator.hasNext()) {
next = null;
} else {
next = iterator.next();
}
return CompletableFuture.completedFuture(next);
}
}).when(mockController).listStreams(scope);
assertTrue(streamManager.deleteScope(scope, true));
}
Aggregations