Search in sources :

Example 66 with StreamConfiguration

use of io.pravega.client.stream.StreamConfiguration in project pravega by pravega.

the class StreamMetaDataTests method testListReaderGroups.

/**
 * Test for listReaderGroups REST API.
 */
@Test
public void testListReaderGroups() {
    final String resourceURI = getURI() + "v1/scopes/scope1/readergroups";
    final StreamConfiguration streamconf1 = StreamConfiguration.builder().scope(scope1).streamName(stream1).scalingPolicy(ScalingPolicy.fixed(1)).build();
    final StreamConfiguration streamconf2 = StreamConfiguration.builder().scope(scope1).streamName(stream2).scalingPolicy(ScalingPolicy.fixed(1)).build();
    final StreamConfiguration readerGroup1 = StreamConfiguration.builder().scope(scope1).streamName(getStreamForReaderGroup("readerGroup1")).scalingPolicy(ScalingPolicy.fixed(1)).build();
    final StreamConfiguration readerGroup2 = StreamConfiguration.builder().scope(scope1).streamName(getStreamForReaderGroup("readerGroup2")).scalingPolicy(ScalingPolicy.fixed(1)).build();
    // Fetch reader groups list.
    List<StreamConfiguration> streamsList = Arrays.asList(streamconf1, streamconf2, readerGroup1, readerGroup2);
    when(mockControllerService.listStreamsInScope(scope1)).thenReturn(CompletableFuture.completedFuture(streamsList));
    Response response = addAuthHeaders(client.target(resourceURI).request()).buildGet().invoke();
    assertEquals("List Reader Groups response code", 200, response.getStatus());
    assertTrue(response.bufferEntity());
    final ReaderGroupsList readerGroupsList1 = response.readEntity(ReaderGroupsList.class);
    assertEquals("List count", readerGroupsList1.getReaderGroups().size(), 2);
    assertEquals("List element", readerGroupsList1.getReaderGroups().get(0).getReaderGroupName(), "readerGroup1");
    assertEquals("List element", readerGroupsList1.getReaderGroups().get(1).getReaderGroupName(), "readerGroup2");
    response.close();
    // Test for list reader groups for non-existing scope.
    final CompletableFuture<List<StreamConfiguration>> completableFuture1 = new CompletableFuture<>();
    completableFuture1.completeExceptionally(StoreException.create(StoreException.Type.DATA_NOT_FOUND, "scope1"));
    when(mockControllerService.listStreamsInScope("scope1")).thenReturn(completableFuture1);
    response = addAuthHeaders(client.target(resourceURI).request()).buildGet().invoke();
    assertEquals("List Reader Groups response code", 404, response.getStatus());
    response.close();
    // Test for list reader groups failure.
    final CompletableFuture<List<StreamConfiguration>> completableFuture = new CompletableFuture<>();
    completableFuture.completeExceptionally(new Exception());
    when(mockControllerService.listStreamsInScope("scope1")).thenReturn(completableFuture);
    response = addAuthHeaders(client.target(resourceURI).request()).buildGet().invoke();
    assertEquals("List Reader Groups response code", 500, response.getStatus());
    response.close();
    // Test to list large number of reader groups.
    streamsList = Collections.nCopies(50000, readerGroup1);
    when(mockControllerService.listStreamsInScope("scope1")).thenReturn(CompletableFuture.completedFuture(streamsList));
    response = addAuthHeaders(client.target(resourceURI).request()).buildGet().invoke();
    assertEquals("List Reader Groups response code", 200, response.getStatus());
    assertTrue(response.bufferEntity());
    final ReaderGroupsList readerGroupsList = response.readEntity(ReaderGroupsList.class);
    assertEquals("List count", 50000, readerGroupsList.getReaderGroups().size());
    response.close();
}
Also used : Response(javax.ws.rs.core.Response) CompletableFuture(java.util.concurrent.CompletableFuture) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) StreamsList(io.pravega.controller.server.rest.generated.model.StreamsList) List(java.util.List) ScopesList(io.pravega.controller.server.rest.generated.model.ScopesList) ArrayList(java.util.ArrayList) ReaderGroupsList(io.pravega.controller.server.rest.generated.model.ReaderGroupsList) StoreException(io.pravega.controller.store.stream.StoreException) ExecutionException(java.util.concurrent.ExecutionException) ReaderGroupsList(io.pravega.controller.server.rest.generated.model.ReaderGroupsList) Test(org.junit.Test)

Example 67 with StreamConfiguration

use of io.pravega.client.stream.StreamConfiguration in project pravega by pravega.

the class ControllerServiceImplTest method sealStreamTests.

@Test
public void sealStreamTests() {
    CreateScopeStatus createScopeStatus;
    CreateStreamStatus createStreamStatus;
    UpdateStreamStatus updateStreamStatus;
    final StreamConfiguration configuration1 = StreamConfiguration.builder().scope(SCOPE1).streamName(STREAM1).scalingPolicy(ScalingPolicy.fixed(4)).build();
    // Create a test scope.
    ResultObserver<CreateScopeStatus> result1 = new ResultObserver<>();
    this.controllerService.createScope(ModelHelper.createScopeInfo(SCOPE1), result1);
    createScopeStatus = result1.get();
    assertEquals("Create Scope", CreateScopeStatus.Status.SUCCESS, createScopeStatus.getStatus());
    // Create a test stream.
    ResultObserver<CreateStreamStatus> result2 = new ResultObserver<>();
    this.controllerService.createStream(ModelHelper.decode(configuration1), result2);
    createStreamStatus = result2.get();
    assertEquals("Create stream", CreateStreamStatus.Status.SUCCESS, createStreamStatus.getStatus());
    // Seal a test stream.
    ResultObserver<UpdateStreamStatus> result3 = new ResultObserver<>();
    this.controllerService.sealStream(ModelHelper.createStreamInfo(SCOPE1, STREAM1), result3);
    updateStreamStatus = result3.get();
    assertEquals("Seal Stream", UpdateStreamStatus.Status.SUCCESS, updateStreamStatus.getStatus());
    // Seal a non-existent stream.
    ResultObserver<UpdateStreamStatus> result4 = new ResultObserver<>();
    this.controllerService.sealStream(ModelHelper.createStreamInfo(SCOPE1, "dummyStream"), result4);
    updateStreamStatus = result4.get();
    assertEquals("Seal non-existent stream", UpdateStreamStatus.Status.STREAM_NOT_FOUND, updateStreamStatus.getStatus());
    // Seal a non-existent stream.
    ResultObserver<UpdateStreamStatus> result5 = new ResultObserver<>();
    this.controllerService.sealStream(ModelHelper.createStreamInfo("dummyScope", STREAM1), result5);
    updateStreamStatus = result5.get();
    assertEquals("Seal non-existent stream", UpdateStreamStatus.Status.STREAM_NOT_FOUND, updateStreamStatus.getStatus());
}
Also used : UpdateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.UpdateStreamStatus) CreateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateStreamStatus) CreateScopeStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateScopeStatus) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) Test(org.junit.Test)

Example 68 with StreamConfiguration

use of io.pravega.client.stream.StreamConfiguration in project pravega by pravega.

the class ControllerServiceImplTest method createStreamTests.

@Test
public void createStreamTests() {
    final ScalingPolicy policy1 = ScalingPolicy.fixed(2);
    final ScalingPolicy policy2 = ScalingPolicy.fixed(3);
    final StreamConfiguration configuration1 = StreamConfiguration.builder().scope(SCOPE1).streamName(STREAM1).scalingPolicy(policy1).build();
    final StreamConfiguration configuration2 = StreamConfiguration.builder().scope(SCOPE1).streamName(STREAM2).scalingPolicy(policy2).build();
    final StreamConfiguration configuration3 = StreamConfiguration.builder().scope("SCOPE3").streamName(STREAM2).scalingPolicy(policy2).build();
    CreateStreamStatus status;
    // region checkStream
    ResultObserver<CreateScopeStatus> result = new ResultObserver<>();
    this.controllerService.createScope(ScopeInfo.newBuilder().setScope(SCOPE1).build(), result);
    Assert.assertEquals(result.get().getStatus(), CreateScopeStatus.Status.SUCCESS);
    ResultObserver<CreateStreamStatus> result1 = new ResultObserver<>();
    this.controllerService.createStream(ModelHelper.decode(configuration1), result1);
    status = result1.get();
    Assert.assertEquals(status.getStatus(), CreateStreamStatus.Status.SUCCESS);
    ResultObserver<CreateStreamStatus> result2 = new ResultObserver<>();
    this.controllerService.createStream(ModelHelper.decode(configuration2), result2);
    status = result2.get();
    Assert.assertEquals(status.getStatus(), CreateStreamStatus.Status.SUCCESS);
    // endregion
    // region duplicate create stream
    ResultObserver<CreateStreamStatus> result3 = new ResultObserver<>();
    this.controllerService.createStream(ModelHelper.decode(configuration1), result3);
    status = result3.get();
    Assert.assertEquals(status.getStatus(), CreateStreamStatus.Status.STREAM_EXISTS);
    // endregion
    // create stream for non-existent scope
    ResultObserver<CreateStreamStatus> result4 = new ResultObserver<>();
    this.controllerService.createStream(ModelHelper.decode(configuration3), result4);
    status = result4.get();
    Assert.assertEquals(status.getStatus(), CreateStreamStatus.Status.SCOPE_NOT_FOUND);
    // create stream with invalid stream name "abc/def"
    ResultObserver<CreateStreamStatus> result5 = new ResultObserver<>();
    final StreamConfiguration configuration4 = StreamConfiguration.builder().scope("SCOPE3").streamName("abc/def").scalingPolicy(policy2).build();
    this.controllerService.createStream(ModelHelper.decode(configuration4), result5);
    status = result5.get();
    assertEquals(status.getStatus(), CreateStreamStatus.Status.INVALID_STREAM_NAME);
    // Create stream with an internal stream name.
    ResultObserver<CreateStreamStatus> result6 = new ResultObserver<>();
    final StreamConfiguration configuration6 = StreamConfiguration.builder().scope(SCOPE1).streamName(NameUtils.getInternalNameForStream("abcdef")).scalingPolicy(policy2).build();
    this.controllerService.createStream(ModelHelper.decode(configuration6), result6);
    status = result6.get();
    assertEquals(status.getStatus(), CreateStreamStatus.Status.SUCCESS);
}
Also used : ScalingPolicy(io.pravega.client.stream.ScalingPolicy) CreateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateStreamStatus) CreateScopeStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateScopeStatus) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) Test(org.junit.Test)

Example 69 with StreamConfiguration

use of io.pravega.client.stream.StreamConfiguration in project pravega by pravega.

the class ControllerServiceImplTest method deleteStreamTests.

@Test
public void deleteStreamTests() {
    CreateScopeStatus createScopeStatus;
    CreateStreamStatus createStreamStatus;
    DeleteStreamStatus deleteStreamStatus;
    final StreamConfiguration configuration1 = StreamConfiguration.builder().scope(SCOPE1).streamName(STREAM1).scalingPolicy(ScalingPolicy.fixed(4)).build();
    // Create a test scope.
    ResultObserver<CreateScopeStatus> result1 = new ResultObserver<>();
    this.controllerService.createScope(ModelHelper.createScopeInfo(SCOPE1), result1);
    createScopeStatus = result1.get();
    assertEquals("Create Scope", CreateScopeStatus.Status.SUCCESS, createScopeStatus.getStatus());
    // Try deleting a non-existent stream.
    ResultObserver<DeleteStreamStatus> result2 = new ResultObserver<>();
    this.controllerService.deleteStream(ModelHelper.createStreamInfo(SCOPE3, "dummyStream"), result2);
    deleteStreamStatus = result2.get();
    assertEquals("Delete Non-existent stream", DeleteStreamStatus.Status.STREAM_NOT_FOUND, deleteStreamStatus.getStatus());
    // Try deleting a non-existent stream.
    ResultObserver<DeleteStreamStatus> result3 = new ResultObserver<>();
    this.controllerService.deleteStream(ModelHelper.createStreamInfo("dummyScope", "dummyStream"), result3);
    deleteStreamStatus = result3.get();
    assertEquals("Delete Non-existent stream", DeleteStreamStatus.Status.STREAM_NOT_FOUND, deleteStreamStatus.getStatus());
    // Create a test stream.
    ResultObserver<CreateStreamStatus> result4 = new ResultObserver<>();
    this.controllerService.createStream(ModelHelper.decode(configuration1), result4);
    createStreamStatus = result4.get();
    Assert.assertEquals("Create stream", CreateStreamStatus.Status.SUCCESS, createStreamStatus.getStatus());
    // Try deleting the test stream without sealing it first.
    ResultObserver<DeleteStreamStatus> result5 = new ResultObserver<>();
    this.controllerService.deleteStream(ModelHelper.createStreamInfo(SCOPE1, STREAM1), result5);
    deleteStreamStatus = result5.get();
    assertEquals("Delete non-sealed stream", DeleteStreamStatus.Status.STREAM_NOT_SEALED, deleteStreamStatus.getStatus());
    // Seal the test stream.
    ResultObserver<UpdateStreamStatus> result6 = new ResultObserver<>();
    this.controllerService.sealStream(ModelHelper.createStreamInfo(SCOPE1, STREAM1), result6);
    UpdateStreamStatus updateStreamStatus = result6.get();
    assertEquals("Seal stream", UpdateStreamStatus.Status.SUCCESS, updateStreamStatus.getStatus());
    // Delete the sealed stream.
    ResultObserver<DeleteStreamStatus> result7 = new ResultObserver<>();
    this.controllerService.deleteStream(ModelHelper.createStreamInfo(SCOPE1, STREAM1), result7);
    deleteStreamStatus = result7.get();
    assertEquals("Delete sealed stream", DeleteStreamStatus.Status.SUCCESS, deleteStreamStatus.getStatus());
}
Also used : UpdateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.UpdateStreamStatus) CreateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateStreamStatus) DeleteStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.DeleteStreamStatus) CreateScopeStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateScopeStatus) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) Test(org.junit.Test)

Example 70 with StreamConfiguration

use of io.pravega.client.stream.StreamConfiguration in project pravega by pravega.

the class ControllerServiceImplTest method deleteScopeTests.

@Test
public void deleteScopeTests() {
    CreateScopeStatus createScopeStatus;
    DeleteScopeStatus deleteScopeStatus;
    CreateStreamStatus createStreamStatus;
    // Delete empty scope (containing no streams) SCOPE3
    ResultObserver<CreateScopeStatus> result1 = new ResultObserver<>();
    this.controllerService.createScope(ModelHelper.createScopeInfo(SCOPE3), result1);
    createScopeStatus = result1.get();
    assertEquals("Create Scope", CreateScopeStatus.Status.SUCCESS, createScopeStatus.getStatus());
    ResultObserver<DeleteScopeStatus> result2 = new ResultObserver<>();
    this.controllerService.deleteScope(ModelHelper.createScopeInfo(SCOPE3), result2);
    deleteScopeStatus = result2.get();
    assertEquals("Delete Empty scope", DeleteScopeStatus.Status.SUCCESS, deleteScopeStatus.getStatus());
    // To verify that SCOPE3 is infact deleted in above delete call
    ResultObserver<DeleteScopeStatus> result7 = new ResultObserver<>();
    this.controllerService.deleteScope(ModelHelper.createScopeInfo(SCOPE3), result7);
    deleteScopeStatus = result7.get();
    assertEquals("Verify that Scope3 is infact deleted", DeleteScopeStatus.Status.SCOPE_NOT_FOUND, deleteScopeStatus.getStatus());
    // Delete Non-empty Scope SCOPE2
    ResultObserver<CreateScopeStatus> result3 = new ResultObserver<>();
    this.controllerService.createScope(ModelHelper.createScopeInfo(SCOPE2), result3);
    createScopeStatus = result3.get();
    assertEquals("Create Scope", CreateScopeStatus.Status.SUCCESS, createScopeStatus.getStatus());
    final ScalingPolicy policy1 = ScalingPolicy.fixed(2);
    final StreamConfiguration configuration1 = StreamConfiguration.builder().scope(SCOPE2).streamName(STREAM1).scalingPolicy(policy1).build();
    ResultObserver<CreateStreamStatus> result4 = new ResultObserver<>();
    this.controllerService.createStream(ModelHelper.decode(configuration1), result4);
    createStreamStatus = result4.get();
    assertEquals(createStreamStatus.getStatus(), CreateStreamStatus.Status.SUCCESS);
    ResultObserver<DeleteScopeStatus> result5 = new ResultObserver<>();
    this.controllerService.deleteScope(ModelHelper.createScopeInfo(SCOPE2), result5);
    deleteScopeStatus = result5.get();
    assertEquals("Delete non empty scope", DeleteScopeStatus.Status.SCOPE_NOT_EMPTY, deleteScopeStatus.getStatus());
    // Delete Non-existent scope SCOPE3
    ResultObserver<DeleteScopeStatus> result6 = new ResultObserver<>();
    this.controllerService.deleteScope(ModelHelper.createScopeInfo("SCOPE3"), result6);
    deleteScopeStatus = result6.get();
    assertEquals("Delete non existent scope", DeleteScopeStatus.Status.SCOPE_NOT_FOUND, deleteScopeStatus.getStatus());
}
Also used : ScalingPolicy(io.pravega.client.stream.ScalingPolicy) CreateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateStreamStatus) CreateScopeStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateScopeStatus) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) DeleteScopeStatus(io.pravega.controller.stream.api.grpc.v1.Controller.DeleteScopeStatus) Test(org.junit.Test)

Aggregations

StreamConfiguration (io.pravega.client.stream.StreamConfiguration)80 Test (org.junit.Test)67 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)44 HashMap (java.util.HashMap)21 ArrayList (java.util.ArrayList)20 Controller (io.pravega.client.stream.impl.Controller)19 TestingServerStarter (io.pravega.test.common.TestingServerStarter)17 List (java.util.List)17 Cleanup (lombok.Cleanup)17 ConnectionFactoryImpl (io.pravega.client.netty.impl.ConnectionFactoryImpl)16 CompletableFuture (java.util.concurrent.CompletableFuture)16 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)16 TestingServer (org.apache.curator.test.TestingServer)16 Before (org.junit.Before)16 ClientFactory (io.pravega.client.ClientFactory)15 ClientFactoryImpl (io.pravega.client.stream.impl.ClientFactoryImpl)15 Executors (java.util.concurrent.Executors)15 After (org.junit.After)15 Assert.assertEquals (org.junit.Assert.assertEquals)15 Map (java.util.Map)14