Search in sources :

Example 96 with PravegaNodeUri

use of io.pravega.shared.protocol.netty.PravegaNodeUri in project pravega by pravega.

the class ControllerImplTest method testGetURI.

@Test
public void testGetURI() throws Exception {
    CompletableFuture<PravegaNodeUri> endpointForSegment;
    endpointForSegment = controllerClient.getEndpointForSegment("scope1/stream1/0");
    assertEquals(new PravegaNodeUri("localhost", SERVICE_PORT), endpointForSegment.get());
    endpointForSegment = controllerClient.getEndpointForSegment("scope1/stream2/0");
    AssertExtensions.assertThrows("Should throw Exception", endpointForSegment, throwable -> true);
}
Also used : PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) Test(org.junit.Test)

Example 97 with PravegaNodeUri

use of io.pravega.shared.protocol.netty.PravegaNodeUri in project pravega by pravega.

the class ControllerImplLBTest method testDiscoveryFailover.

@Test
public void testDiscoveryFailover() throws Exception {
    final int serverPort1 = testRPCServer1.getPort();
    final int serverPort2 = testRPCServer2.getPort();
    // Use 2 servers for discovery. Bring down the first server and ensure discovery happens using the other one.
    testRPCServer1.shutdownNow();
    testRPCServer1.awaitTermination();
    Assert.assertTrue(testRPCServer1.isTerminated());
    @Cleanup("shutdown") InlineExecutor executor = new InlineExecutor();
    final ControllerImpl controllerClient = new ControllerImpl(ControllerImplConfig.builder().clientConfig(ClientConfig.builder().controllerURI(URI.create("pravega://localhost:" + serverPort1 + ",localhost:" + serverPort2)).build()).retryAttempts(1).build(), executor);
    // Verify that we can read from the 2 live servers.
    Set<PravegaNodeUri> uris = fetchFromServers(controllerClient, 2);
    Assert.assertEquals(2, uris.size());
    Assert.assertFalse(uris.contains(new PravegaNodeUri("localhost1", 1)));
    // Verify no RPC requests fail due to the failed servers.
    Assert.assertTrue(verifyNoFailures(controllerClient));
    // Bring down another one and verify.
    testRPCServer2.shutdownNow();
    testRPCServer2.awaitTermination();
    Assert.assertTrue(testRPCServer2.isTerminated());
    uris = fetchFromServers(controllerClient, 1);
    Assert.assertEquals(1, uris.size());
    Assert.assertTrue(uris.contains(new PravegaNodeUri("localhost3", 3)));
    // Verify no RPC requests fail due to the failed servers.
    Assert.assertTrue(verifyNoFailures(controllerClient));
    // Bring down all and verify.
    testRPCServer3.shutdownNow();
    testRPCServer3.awaitTermination();
    Assert.assertTrue(testRPCServer3.isTerminated());
    final ControllerImpl client = new ControllerImpl(ControllerImplConfig.builder().clientConfig(ClientConfig.builder().controllerURI(URI.create("pravega://localhost:" + serverPort1 + ",localhost:" + serverPort2)).build()).retryAttempts(1).build(), executor);
    AssertExtensions.assertThrows(RetriesExhaustedException.class, () -> client.getEndpointForSegment("a/b/0").get());
}
Also used : PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) InlineExecutor(io.pravega.test.common.InlineExecutor) Cleanup(lombok.Cleanup) Test(org.junit.Test)

Example 98 with PravegaNodeUri

use of io.pravega.shared.protocol.netty.PravegaNodeUri in project pravega by pravega.

the class ControllerImplLBTest method testDirectFailover.

@Test
public void testDirectFailover() throws Exception {
    final int serverPort1 = testRPCServer1.getPort();
    final int serverPort2 = testRPCServer2.getPort();
    final int serverPort3 = testRPCServer3.getPort();
    // Bring down the first server and verify we can fallback to the remaining 2 servers.
    testRPCServer1.shutdownNow();
    testRPCServer1.awaitTermination();
    Assert.assertTrue(testRPCServer1.isTerminated());
    @Cleanup("shutdown") InlineExecutor executor = new InlineExecutor();
    final ControllerImpl controllerClient = new ControllerImpl(ControllerImplConfig.builder().clientConfig(ClientConfig.builder().controllerURI(URI.create("tcp://localhost:" + serverPort1 + ",localhost:" + serverPort2 + ",localhost:" + serverPort3)).build()).retryAttempts(1).build(), executor);
    Set<PravegaNodeUri> uris = fetchFromServers(controllerClient, 2);
    Assert.assertEquals(2, uris.size());
    Assert.assertFalse(uris.contains(new PravegaNodeUri("localhost1", 1)));
    // Verify no RPC requests fail due to the failed servers.
    Assert.assertTrue(verifyNoFailures(controllerClient));
    // Bring down another one and verify.
    testRPCServer2.shutdownNow();
    testRPCServer2.awaitTermination();
    Assert.assertTrue(testRPCServer2.isTerminated());
    uris = fetchFromServers(controllerClient, 1);
    Assert.assertEquals(1, uris.size());
    Assert.assertTrue(uris.contains(new PravegaNodeUri("localhost3", 3)));
    // Verify no RPC requests fail due to the failed servers.
    Assert.assertTrue(verifyNoFailures(controllerClient));
    // Bring down all and verify.
    testRPCServer3.shutdownNow();
    testRPCServer3.awaitTermination();
    Assert.assertTrue(testRPCServer3.isTerminated());
    AssertExtensions.assertThrows(RetriesExhaustedException.class, () -> controllerClient.getEndpointForSegment("a/b/0").get());
}
Also used : PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) InlineExecutor(io.pravega.test.common.InlineExecutor) Cleanup(lombok.Cleanup) Test(org.junit.Test)

Example 99 with PravegaNodeUri

use of io.pravega.shared.protocol.netty.PravegaNodeUri in project pravega by pravega.

the class MockController method createStream.

@Override
@Synchronized
public CompletableFuture<Boolean> createStream(StreamConfiguration streamConfig) {
    Stream stream = new StreamImpl(streamConfig.getScope(), streamConfig.getStreamName());
    if (createdStreams.get(stream) != null) {
        return CompletableFuture.completedFuture(false);
    }
    if (createdScopes.get(streamConfig.getScope()) == null) {
        return Futures.failedFuture(new IllegalArgumentException("Scope does not exit."));
    }
    createdStreams.put(stream, streamConfig);
    createdScopes.get(streamConfig.getScope()).add(stream);
    for (Segment segment : getSegmentsForStream(stream)) {
        createSegment(segment.getScopedName(), new PravegaNodeUri(endpoint, port));
    }
    return CompletableFuture.completedFuture(true);
}
Also used : PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) StreamImpl(io.pravega.client.stream.impl.StreamImpl) Stream(io.pravega.client.stream.Stream) CreateSegment(io.pravega.shared.protocol.netty.WireCommands.CreateSegment) Segment(io.pravega.client.segment.impl.Segment) DeleteSegment(io.pravega.shared.protocol.netty.WireCommands.DeleteSegment) Synchronized(lombok.Synchronized)

Example 100 with PravegaNodeUri

use of io.pravega.shared.protocol.netty.PravegaNodeUri in project pravega by pravega.

the class AppendTest method appendALotOfData.

@Test(timeout = 100000)
public void appendALotOfData() {
    String endpoint = "localhost";
    String scope = "Scope";
    String streamName = "appendALotOfData";
    int port = TestUtils.getAvailableListenPort();
    long heapSize = Runtime.getRuntime().maxMemory();
    long messageSize = Math.min(1024 * 1024, heapSize / 20000);
    ByteBuffer payload = ByteBuffer.allocate((int) messageSize);
    StreamSegmentStore store = SERVICE_BUILDER.createStreamSegmentService();
    TableStore tableStore = SERVICE_BUILDER.createTableStoreService();
    @Cleanup("shutdown") InlineExecutor tokenExpiryExecutor = new InlineExecutor();
    @Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, port, store, tableStore, tokenExpiryExecutor);
    server.startListening();
    ClientConfig config = ClientConfig.builder().build();
    SocketConnectionFactoryImpl clientCF = new SocketConnectionFactoryImpl(config);
    @Cleanup ConnectionPoolImpl connectionPool = new ConnectionPoolImpl(config, clientCF);
    Controller controller = new MockController(endpoint, port, connectionPool, true);
    @Cleanup StreamManagerImpl streamManager = new StreamManagerImpl(controller, connectionPool);
    streamManager.createScope(scope);
    @Cleanup ClientFactoryImpl clientFactory = new ClientFactoryImpl(scope, controller, config);
    streamManager.createStream("Scope", streamName, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build());
    @Cleanup EventStreamWriter<ByteBuffer> producer = clientFactory.createEventWriter(streamName, new ByteBufferSerializer(), EventWriterConfig.builder().build());
    @Cleanup RawClient rawClient = new RawClient(new PravegaNodeUri(endpoint, port), connectionPool);
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 100; j++) {
            producer.writeEvent(payload.slice());
        }
        producer.flush();
        long requestId = rawClient.getFlow().getNextSequenceNumber();
        String scopedName = new Segment(scope, streamName, 0).getScopedName();
        WireCommands.TruncateSegment request = new WireCommands.TruncateSegment(requestId, scopedName, i * 100L * (payload.remaining() + TYPE_PLUS_LENGTH_SIZE), "");
        Reply reply = rawClient.sendRequest(requestId, request).join();
        assertFalse(reply.toString(), reply.isFailure());
    }
    producer.close();
}
Also used : ConnectionPoolImpl(io.pravega.client.connection.impl.ConnectionPoolImpl) RawClient(io.pravega.client.connection.impl.RawClient) StreamManagerImpl(io.pravega.client.admin.impl.StreamManagerImpl) ByteBufferSerializer(io.pravega.client.stream.impl.ByteBufferSerializer) Cleanup(lombok.Cleanup) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) CreateSegment(io.pravega.shared.protocol.netty.WireCommands.CreateSegment) Segment(io.pravega.client.segment.impl.Segment) NoSuchSegment(io.pravega.shared.protocol.netty.WireCommands.NoSuchSegment) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) InlineExecutor(io.pravega.test.common.InlineExecutor) ClientConfig(io.pravega.client.ClientConfig) WireCommands(io.pravega.shared.protocol.netty.WireCommands) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) MockController(io.pravega.client.stream.mock.MockController) Controller(io.pravega.client.control.impl.Controller) ByteBuffer(java.nio.ByteBuffer) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) MockController(io.pravega.client.stream.mock.MockController) Reply(io.pravega.shared.protocol.netty.Reply) Test(org.junit.Test)

Aggregations

PravegaNodeUri (io.pravega.shared.protocol.netty.PravegaNodeUri)185 Test (org.junit.Test)154 Cleanup (lombok.Cleanup)124 MockController (io.pravega.client.stream.mock.MockController)122 MockConnectionFactoryImpl (io.pravega.client.stream.mock.MockConnectionFactoryImpl)119 ClientConnection (io.pravega.client.connection.impl.ClientConnection)81 WireCommands (io.pravega.shared.protocol.netty.WireCommands)70 UUID (java.util.UUID)57 Segment (io.pravega.client.segment.impl.Segment)49 CompletableFuture (java.util.concurrent.CompletableFuture)44 InvocationOnMock (org.mockito.invocation.InvocationOnMock)44 ReplyProcessor (io.pravega.shared.protocol.netty.ReplyProcessor)40 ConnectionFailedException (io.pravega.shared.protocol.netty.ConnectionFailedException)35 AppendSetup (io.pravega.shared.protocol.netty.WireCommands.AppendSetup)35 SetupAppend (io.pravega.shared.protocol.netty.WireCommands.SetupAppend)35 ByteBuffer (java.nio.ByteBuffer)34 Append (io.pravega.shared.protocol.netty.Append)33 AtomicLong (java.util.concurrent.atomic.AtomicLong)31 MockSegmentStreamFactory (io.pravega.client.stream.mock.MockSegmentStreamFactory)30 InOrder (org.mockito.InOrder)28