Search in sources :

Example 1 with ControllerFailureException

use of io.pravega.client.control.impl.ControllerFailureException in project pravega by pravega.

the class StreamManagerImpl method deleteScope.

/**
 * A new API is created hence this is going to be deprecated.
 *
 * @deprecated As of Pravega release 0.11.0, replaced by {@link #deleteScopeRecursive(String)}.
 */
@Override
@Deprecated
public boolean deleteScope(String scopeName, boolean forceDelete) throws DeleteScopeFailedException {
    NameUtils.validateUserScopeName(scopeName);
    if (forceDelete) {
        log.info("Deleting scope recursively: {}", scopeName);
        List<String> readerGroupList = new ArrayList<>();
        Iterator<Stream> iterator = listStreams(scopeName);
        while (iterator.hasNext()) {
            Stream stream = iterator.next();
            if (stream.getStreamName().startsWith(READER_GROUP_STREAM_PREFIX)) {
                readerGroupList.add(stream.getStreamName().substring(READER_GROUP_STREAM_PREFIX.length()));
            }
            try {
                Futures.getThrowingException(Futures.exceptionallyExpecting(controller.sealStream(stream.getScope(), stream.getStreamName()), e -> {
                    Throwable unwrap = Exceptions.unwrap(e);
                    // ignore failures if the stream doesn't exist or we are unable to seal it.
                    return unwrap instanceof InvalidStreamException || unwrap instanceof ControllerFailureException;
                }, false).thenCompose(sealed -> controller.deleteStream(stream.getScope(), stream.getStreamName())));
            } catch (Exception e) {
                String message = String.format("Failed to seal and delete stream %s", stream.getStreamName());
                throw new DeleteScopeFailedException(message, e);
            }
        }
        Iterator<KeyValueTableInfo> kvtIterator = controller.listKeyValueTables(scopeName).asIterator();
        while (kvtIterator.hasNext()) {
            KeyValueTableInfo kvt = kvtIterator.next();
            try {
                Futures.getThrowingException(controller.deleteKeyValueTable(scopeName, kvt.getKeyValueTableName()));
            } catch (Exception e) {
                String message = String.format("Failed to delete key-value table %s", kvt.getKeyValueTableName());
                throw new DeleteScopeFailedException(message, e);
            }
        }
        for (String groupName : readerGroupList) {
            try {
                Futures.getThrowingException(controller.getReaderGroupConfig(scopeName, groupName).thenCompose(conf -> controller.deleteReaderGroup(scopeName, groupName, conf.getReaderGroupId())));
            } catch (Exception e) {
                if (Exceptions.unwrap(e) instanceof ReaderGroupNotFoundException) {
                    continue;
                }
                String message = String.format("Failed to delete reader group %s", groupName);
                throw new DeleteScopeFailedException(message, e);
            }
        }
    }
    return Futures.getThrowingException(controller.deleteScope(scopeName));
}
Also used : StreamCut(io.pravega.client.stream.StreamCut) Getter(lombok.Getter) StreamManager(io.pravega.client.admin.StreamManager) Exceptions(io.pravega.common.Exceptions) DeleteScopeFailedException(io.pravega.client.stream.DeleteScopeFailedException) CompletableFuture(java.util.concurrent.CompletableFuture) ConnectionPoolImpl(io.pravega.client.connection.impl.ConnectionPoolImpl) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) ArrayList(java.util.ArrayList) ReaderGroupNotFoundException(io.pravega.client.stream.ReaderGroupNotFoundException) AccessLevel(lombok.AccessLevel) KeyValueTableInfo(io.pravega.client.admin.KeyValueTableInfo) Stream(io.pravega.client.stream.Stream) StreamCutImpl(io.pravega.client.stream.impl.StreamCutImpl) ControllerFailureException(io.pravega.client.control.impl.ControllerFailureException) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) NameUtils(io.pravega.shared.NameUtils) Callbacks(io.pravega.common.function.Callbacks) Iterator(java.util.Iterator) ConnectionPool(io.pravega.client.connection.impl.ConnectionPool) Collection(java.util.Collection) AsyncIterator(io.pravega.common.util.AsyncIterator) StreamInfo(io.pravega.client.admin.StreamInfo) READER_GROUP_STREAM_PREFIX(io.pravega.shared.NameUtils.READER_GROUP_STREAM_PREFIX) ControllerImplConfig(io.pravega.client.control.impl.ControllerImplConfig) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) ControllerImpl(io.pravega.client.control.impl.ControllerImpl) InvalidStreamException(io.pravega.client.stream.InvalidStreamException) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Controller(io.pravega.client.control.impl.Controller) Futures(io.pravega.common.concurrent.Futures) ClientConfig(io.pravega.client.ClientConfig) ArrayList(java.util.ArrayList) InvalidStreamException(io.pravega.client.stream.InvalidStreamException) DeleteScopeFailedException(io.pravega.client.stream.DeleteScopeFailedException) ReaderGroupNotFoundException(io.pravega.client.stream.ReaderGroupNotFoundException) ControllerFailureException(io.pravega.client.control.impl.ControllerFailureException) InvalidStreamException(io.pravega.client.stream.InvalidStreamException) KeyValueTableInfo(io.pravega.client.admin.KeyValueTableInfo) ReaderGroupNotFoundException(io.pravega.client.stream.ReaderGroupNotFoundException) ControllerFailureException(io.pravega.client.control.impl.ControllerFailureException) Stream(io.pravega.client.stream.Stream) DeleteScopeFailedException(io.pravega.client.stream.DeleteScopeFailedException)

Example 2 with ControllerFailureException

use of io.pravega.client.control.impl.ControllerFailureException in project pravega by pravega.

the class StreamManagerImplTest method testForceDeleteScope.

@Test(timeout = 10000)
public void testForceDeleteScope() 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 stream3 = "stream3";
    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());
    streamManager.createStream(scope, stream3, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(3)).build());
    Set<Stream> streams = Sets.newHashSet(streamManager.listStreams(scope));
    assertEquals(3, streams.size());
    assertTrue(streams.stream().anyMatch(x -> x.getStreamName().equals(stream1)));
    assertTrue(streams.stream().anyMatch(x -> x.getStreamName().equals(stream2)));
    assertTrue(streams.stream().anyMatch(x -> x.getStreamName().equals(stream3)));
    // mock controller client to throw exceptions when attempting to seal and delete for stream 1.
    doAnswer(x -> Futures.failedFuture(new ControllerFailureException("Unable to seal stream"))).when(mockController).sealStream(scope, stream1);
    doAnswer(x -> Futures.failedFuture(new IllegalArgumentException("Stream not sealed"))).when(mockController).deleteStream(scope, stream1);
    AssertExtensions.assertThrows("Should have thrown exception", () -> streamManager.deleteScope(scope, true), e -> Exceptions.unwrap(e) instanceof DeleteScopeFailedException);
    // reset mock controller
    reset(mockController);
    // throw invalid stream for stream 2. Delete should happen despite invalid stream exception.
    doAnswer(x -> Futures.failedFuture(new InvalidStreamException("Stream does not exist"))).when(mockController).sealStream(scope, stream2);
    assertTrue(streamManager.deleteScope(scope, true));
}
Also used : Arrays(java.util.Arrays) AssertExtensions(io.pravega.test.common.AssertExtensions) Cleanup(lombok.Cleanup) DeleteScopeFailedException(io.pravega.client.stream.DeleteScopeFailedException) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) KeyValueTableConfiguration(io.pravega.client.tables.KeyValueTableConfiguration) ReaderGroupNotFoundException(io.pravega.client.stream.ReaderGroupNotFoundException) StreamSegments(io.pravega.client.stream.impl.StreamSegments) MockController(io.pravega.client.stream.mock.MockController) ClientConnection(io.pravega.client.connection.impl.ClientConnection) KeyValueTableInfo(io.pravega.client.admin.KeyValueTableInfo) Stream(io.pravega.client.stream.Stream) After(org.junit.After) Mockito.doAnswer(org.mockito.Mockito.doAnswer) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) URI(java.net.URI) Mockito.doReturn(org.mockito.Mockito.doReturn) ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) Set(java.util.Set) StreamInfo(io.pravega.client.admin.StreamInfo) Sets(com.google.common.collect.Sets) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) Assert.assertFalse(org.junit.Assert.assertFalse) TestUtils(io.pravega.test.common.TestUtils) Controller(io.pravega.client.control.impl.Controller) Futures(io.pravega.common.concurrent.Futures) Mockito.mock(org.mockito.Mockito.mock) StreamImpl(io.pravega.client.stream.impl.StreamImpl) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException) StreamManager(io.pravega.client.admin.StreamManager) Exceptions(io.pravega.common.Exceptions) CompletableFuture(java.util.concurrent.CompletableFuture) ConnectionPoolImpl(io.pravega.client.connection.impl.ConnectionPoolImpl) Mockito.spy(org.mockito.Mockito.spy) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Answer(org.mockito.stubbing.Answer) KeyValueTableManager(io.pravega.client.admin.KeyValueTableManager) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Lists(com.google.common.collect.Lists) ControllerFailureException(io.pravega.client.control.impl.ControllerFailureException) Before(org.junit.Before) NameUtils(io.pravega.shared.NameUtils) Iterator(java.util.Iterator) Assert.assertNotNull(org.junit.Assert.assertNotNull) MockConnectionFactoryImpl(io.pravega.client.stream.mock.MockConnectionFactoryImpl) Assert.assertTrue(org.junit.Assert.assertTrue) AsyncIterator(io.pravega.common.util.AsyncIterator) Test(org.junit.Test) WireCommands(io.pravega.shared.protocol.netty.WireCommands) Mockito(org.mockito.Mockito) TreeMap(java.util.TreeMap) InvalidStreamException(io.pravega.client.stream.InvalidStreamException) Assert(org.junit.Assert) Collections(java.util.Collections) Mockito.reset(org.mockito.Mockito.reset) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) Assert.assertEquals(org.junit.Assert.assertEquals) ClientConfig(io.pravega.client.ClientConfig) ConnectionPoolImpl(io.pravega.client.connection.impl.ConnectionPoolImpl) Cleanup(lombok.Cleanup) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) ClientConnection(io.pravega.client.connection.impl.ClientConnection) Stream(io.pravega.client.stream.Stream) DeleteScopeFailedException(io.pravega.client.stream.DeleteScopeFailedException) WireCommands(io.pravega.shared.protocol.netty.WireCommands) InvalidStreamException(io.pravega.client.stream.InvalidStreamException) InvocationOnMock(org.mockito.invocation.InvocationOnMock) StreamManager(io.pravega.client.admin.StreamManager) ControllerFailureException(io.pravega.client.control.impl.ControllerFailureException) MockController(io.pravega.client.stream.mock.MockController) Test(org.junit.Test)

Example 3 with ControllerFailureException

use of io.pravega.client.control.impl.ControllerFailureException in project pravega by pravega.

the class StreamManagerImplTest method testForceDeleteScopeWithKeyValueTables.

@Test(timeout = 10000)
public void testForceDeleteScopeWithKeyValueTables() 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.CreateTableSegment request = (WireCommands.CreateTableSegment) invocation.getArgument(0);
            connectionFactory.getProcessor(location).process(new WireCommands.SegmentCreated(request.getRequestId(), request.getSegment()));
            return null;
        }
    }).when(connection).send(Mockito.any(WireCommands.CreateTableSegment.class));
    Mockito.doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            WireCommands.CreateTableSegment request = invocation.getArgument(0);
            connectionFactory.getProcessor(location).process(new WireCommands.SegmentCreated(request.getRequestId(), request.getSegment()));
            return null;
        }
    }).when(connection).send(Mockito.any(WireCommands.CreateTableSegment.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));
    Mockito.doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            WireCommands.DeleteTableSegment request = invocation.getArgument(0);
            connectionFactory.getProcessor(location).process(new WireCommands.SegmentDeleted(request.getRequestId(), request.getSegment()));
            return null;
        }
    }).when(connection).send(Mockito.any(WireCommands.DeleteTableSegment.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);
    @Cleanup final KeyValueTableManager keyValueTableManager = new KeyValueTableManagerImpl(mockController, connectionFactory);
    String scope = "scope";
    String kvt1 = "kvt1";
    String kvt2 = "kvt2";
    streamManager.createScope(scope);
    KeyValueTableConfiguration kvtConfig = KeyValueTableConfiguration.builder().partitionCount(1).primaryKeyLength(1).secondaryKeyLength(1).build();
    keyValueTableManager.createKeyValueTable(scope, kvt1, kvtConfig);
    keyValueTableManager.createKeyValueTable(scope, kvt2, kvtConfig);
    Set<KeyValueTableInfo> keyValueTables = Sets.newHashSet(keyValueTableManager.listKeyValueTables(scope));
    assertEquals(2, keyValueTables.size());
    assertTrue(keyValueTables.stream().anyMatch(x -> x.getKeyValueTableName().equals(kvt1)));
    assertTrue(keyValueTables.stream().anyMatch(x -> x.getKeyValueTableName().equals(kvt2)));
    // mock controller client to throw exceptions when attempting to delete key value table 1.
    doAnswer(x -> Futures.failedFuture(new ControllerFailureException("Unable to delete key value table"))).when(mockController).deleteKeyValueTable(scope, kvt1);
    AssertExtensions.assertThrows("Should have thrown exception", () -> streamManager.deleteScope(scope, true), e -> Exceptions.unwrap(e) instanceof DeleteScopeFailedException);
    // reset mock controller
    reset(mockController);
    assertTrue(streamManager.deleteScope(scope, true));
}
Also used : KeyValueTableManager(io.pravega.client.admin.KeyValueTableManager) Arrays(java.util.Arrays) AssertExtensions(io.pravega.test.common.AssertExtensions) Cleanup(lombok.Cleanup) DeleteScopeFailedException(io.pravega.client.stream.DeleteScopeFailedException) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) KeyValueTableConfiguration(io.pravega.client.tables.KeyValueTableConfiguration) ReaderGroupNotFoundException(io.pravega.client.stream.ReaderGroupNotFoundException) StreamSegments(io.pravega.client.stream.impl.StreamSegments) MockController(io.pravega.client.stream.mock.MockController) ClientConnection(io.pravega.client.connection.impl.ClientConnection) KeyValueTableInfo(io.pravega.client.admin.KeyValueTableInfo) Stream(io.pravega.client.stream.Stream) After(org.junit.After) Mockito.doAnswer(org.mockito.Mockito.doAnswer) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) URI(java.net.URI) Mockito.doReturn(org.mockito.Mockito.doReturn) ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) Set(java.util.Set) StreamInfo(io.pravega.client.admin.StreamInfo) Sets(com.google.common.collect.Sets) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) Assert.assertFalse(org.junit.Assert.assertFalse) TestUtils(io.pravega.test.common.TestUtils) Controller(io.pravega.client.control.impl.Controller) Futures(io.pravega.common.concurrent.Futures) Mockito.mock(org.mockito.Mockito.mock) StreamImpl(io.pravega.client.stream.impl.StreamImpl) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException) StreamManager(io.pravega.client.admin.StreamManager) Exceptions(io.pravega.common.Exceptions) CompletableFuture(java.util.concurrent.CompletableFuture) ConnectionPoolImpl(io.pravega.client.connection.impl.ConnectionPoolImpl) Mockito.spy(org.mockito.Mockito.spy) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Answer(org.mockito.stubbing.Answer) KeyValueTableManager(io.pravega.client.admin.KeyValueTableManager) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Lists(com.google.common.collect.Lists) ControllerFailureException(io.pravega.client.control.impl.ControllerFailureException) Before(org.junit.Before) NameUtils(io.pravega.shared.NameUtils) Iterator(java.util.Iterator) Assert.assertNotNull(org.junit.Assert.assertNotNull) MockConnectionFactoryImpl(io.pravega.client.stream.mock.MockConnectionFactoryImpl) Assert.assertTrue(org.junit.Assert.assertTrue) AsyncIterator(io.pravega.common.util.AsyncIterator) Test(org.junit.Test) WireCommands(io.pravega.shared.protocol.netty.WireCommands) Mockito(org.mockito.Mockito) TreeMap(java.util.TreeMap) InvalidStreamException(io.pravega.client.stream.InvalidStreamException) Assert(org.junit.Assert) Collections(java.util.Collections) Mockito.reset(org.mockito.Mockito.reset) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) Assert.assertEquals(org.junit.Assert.assertEquals) ClientConfig(io.pravega.client.ClientConfig) ConnectionPoolImpl(io.pravega.client.connection.impl.ConnectionPoolImpl) Cleanup(lombok.Cleanup) KeyValueTableInfo(io.pravega.client.admin.KeyValueTableInfo) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) ClientConnection(io.pravega.client.connection.impl.ClientConnection) DeleteScopeFailedException(io.pravega.client.stream.DeleteScopeFailedException) WireCommands(io.pravega.shared.protocol.netty.WireCommands) KeyValueTableConfiguration(io.pravega.client.tables.KeyValueTableConfiguration) InvocationOnMock(org.mockito.invocation.InvocationOnMock) StreamManager(io.pravega.client.admin.StreamManager) ControllerFailureException(io.pravega.client.control.impl.ControllerFailureException) MockController(io.pravega.client.stream.mock.MockController) Test(org.junit.Test)

Example 4 with ControllerFailureException

use of io.pravega.client.control.impl.ControllerFailureException in project pravega by pravega.

the class SegmentSelectorTest method testControllerNotReachable.

@Test
public void testControllerNotReachable() {
    final Segment segment0 = new Segment(scope, streamName, 0);
    final Segment segment1 = new Segment(scope, streamName, 1);
    final CompletableFuture<Void> writerFuture = new CompletableFuture<>();
    // Setup Mock.
    SegmentOutputStream s0Writer = Mockito.mock(SegmentOutputStream.class);
    SegmentOutputStream s1Writer = Mockito.mock(SegmentOutputStream.class);
    when(s0Writer.getUnackedEventsOnSeal()).thenReturn(ImmutableList.of(PendingEvent.withHeader("0", ByteBuffer.wrap("e".getBytes()), writerFuture)));
    SegmentOutputStreamFactory factory = Mockito.mock(SegmentOutputStreamFactory.class);
    when(factory.createOutputStreamForSegment(eq(segment0), ArgumentMatchers.<Consumer<Segment>>any(), any(EventWriterConfig.class), any(DelegationTokenProvider.class))).thenReturn(s0Writer);
    when(factory.createOutputStreamForSegment(eq(segment1), ArgumentMatchers.<Consumer<Segment>>any(), any(EventWriterConfig.class), any(DelegationTokenProvider.class))).thenReturn(s1Writer);
    Controller controller = Mockito.mock(Controller.class);
    SegmentSelector selector = new SegmentSelector(new StreamImpl(scope, streamName), controller, factory, config, DelegationTokenProviderFactory.createWithEmptyToken());
    TreeMap<Double, SegmentWithRange> segments = new TreeMap<>();
    addNewSegment(segments, 0, 0.0, 0.5);
    addNewSegment(segments, 1, 0.5, 1.0);
    StreamSegments streamSegments = new StreamSegments(segments);
    when(controller.getCurrentSegments(scope, streamName)).thenReturn(CompletableFuture.completedFuture(streamSegments));
    // trigger refresh.
    selector.refreshSegmentEventWriters(segmentSealedCallback);
    // simulate controller failure when controller.getSuccessors() is invoked.
    when(controller.getSuccessors(segment0)).thenAnswer(i -> {
        CompletableFuture<StreamSegmentsWithPredecessors> result = new CompletableFuture<>();
        // Controller client in case of RPC exceptions throws a StatusRuntimeException which is retried by the client.
        // If the controller client is not able to reach the controller after all the retries a RetriesExhaustedException is
        // thrown.
        result.completeExceptionally(new RetriesExhaustedException(new StatusRuntimeException(Status.DATA_LOSS)));
        return result;
    });
    assertEquals(Collections.emptyList(), selector.refreshSegmentEventWritersUponSealed(segment0, segmentSealedCallback));
    assertFutureThrows("Writer Future", writerFuture, t -> t instanceof ControllerFailureException);
}
Also used : Controller(io.pravega.client.control.impl.Controller) TreeMap(java.util.TreeMap) Segment(io.pravega.client.segment.impl.Segment) CompletableFuture(java.util.concurrent.CompletableFuture) SegmentOutputStreamFactory(io.pravega.client.segment.impl.SegmentOutputStreamFactory) EventWriterConfig(io.pravega.client.stream.EventWriterConfig) RetriesExhaustedException(io.pravega.common.util.RetriesExhaustedException) SegmentOutputStream(io.pravega.client.segment.impl.SegmentOutputStream) StatusRuntimeException(io.grpc.StatusRuntimeException) ControllerFailureException(io.pravega.client.control.impl.ControllerFailureException) DelegationTokenProvider(io.pravega.client.security.auth.DelegationTokenProvider) Test(org.junit.Test)

Example 5 with ControllerFailureException

use of io.pravega.client.control.impl.ControllerFailureException in project pravega by pravega.

the class LocalControllerTest method testUpdateSubscriberStreamCut.

@Test(timeout = 10000)
public void testUpdateSubscriberStreamCut() throws ExecutionException, InterruptedException {
    UUID someId = UUID.randomUUID();
    StreamCut streamCut = new StreamCutImpl(new StreamImpl("scope", "stream"), Collections.emptyMap());
    when(this.mockControllerService.updateSubscriberStreamCut(anyString(), anyString(), anyString(), any(), anyLong(), any(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.UpdateSubscriberStatus.newBuilder().setStatus(Controller.UpdateSubscriberStatus.Status.SUCCESS).build()));
    Assert.assertTrue(this.testController.updateSubscriberStreamCut("scope", "stream", "subscriber", someId, 0L, streamCut).join());
    when(this.mockControllerService.updateSubscriberStreamCut(anyString(), anyString(), anyString(), any(), anyLong(), any(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.UpdateSubscriberStatus.newBuilder().setStatus(Controller.UpdateSubscriberStatus.Status.FAILURE).build()));
    assertThrows("Expected ControllerFailureException", () -> this.testController.updateSubscriberStreamCut("scope", "stream", "subscriber", someId, 0L, streamCut).join(), ex -> ex instanceof ControllerFailureException);
    when(this.mockControllerService.updateSubscriberStreamCut(anyString(), anyString(), anyString(), any(), anyLong(), any(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.UpdateSubscriberStatus.newBuilder().setStatus(Controller.UpdateSubscriberStatus.Status.STREAM_NOT_FOUND).build()));
    assertThrows("Expected IllegalArgumentException", () -> this.testController.updateSubscriberStreamCut("scope", "stream", "subscriber", someId, 0L, streamCut).join(), ex -> ex instanceof IllegalArgumentException);
    when(this.mockControllerService.updateSubscriberStreamCut(anyString(), anyString(), anyString(), any(), anyLong(), any(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.UpdateSubscriberStatus.newBuilder().setStatus(Controller.UpdateSubscriberStatus.Status.SUBSCRIBER_NOT_FOUND).build()));
    assertThrows("Expected IllegalArgumentException", () -> this.testController.updateSubscriberStreamCut("scope", "stream", "subscriber", someId, 0L, streamCut).join(), ex -> ex instanceof IllegalArgumentException);
    when(this.mockControllerService.updateSubscriberStreamCut(anyString(), anyString(), anyString(), any(), anyLong(), any(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.UpdateSubscriberStatus.newBuilder().setStatus(Controller.UpdateSubscriberStatus.Status.GENERATION_MISMATCH).build()));
    assertThrows("Expected IllegalArgumentException", () -> this.testController.updateSubscriberStreamCut("scope", "stream", "subscriber", someId, 0L, streamCut).join(), ex -> ex instanceof IllegalArgumentException);
}
Also used : StreamCut(io.pravega.client.stream.StreamCut) StreamCutImpl(io.pravega.client.stream.impl.StreamCutImpl) StreamImpl(io.pravega.client.stream.impl.StreamImpl) ControllerFailureException(io.pravega.client.control.impl.ControllerFailureException) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

ControllerFailureException (io.pravega.client.control.impl.ControllerFailureException)15 Test (org.junit.Test)12 Stream (io.pravega.client.stream.Stream)9 Controller (io.pravega.client.control.impl.Controller)6 ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)6 StreamImpl (io.pravega.client.stream.impl.StreamImpl)6 Futures (io.pravega.common.concurrent.Futures)6 ArrayList (java.util.ArrayList)6 Iterator (java.util.Iterator)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 KeyValueTableInfo (io.pravega.client.admin.KeyValueTableInfo)5 Segment (io.pravega.client.segment.impl.Segment)5 InvalidStreamException (io.pravega.client.stream.InvalidStreamException)5 StreamCut (io.pravega.client.stream.StreamCut)5 StreamCutImpl (io.pravega.client.stream.impl.StreamCutImpl)5 Exceptions (io.pravega.common.Exceptions)5 AsyncIterator (io.pravega.common.util.AsyncIterator)5 ClientConfig (io.pravega.client.ClientConfig)4 StreamInfo (io.pravega.client.admin.StreamInfo)4 StreamManager (io.pravega.client.admin.StreamManager)4