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);
}
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());
}
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());
}
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);
}
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();
}
Aggregations