use of io.pravega.shared.protocol.netty.PravegaNodeUri in project pravega by pravega.
the class RawClientTest method testHello.
@Test
public void testHello() throws ConnectionFailedException {
PravegaNodeUri endpoint = new PravegaNodeUri("localhost", -1);
@Cleanup MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
@Cleanup MockController controller = new MockController(endpoint.getEndpoint(), endpoint.getPort(), connectionFactory);
ClientConnection connection = Mockito.mock(ClientConnection.class);
connectionFactory.provideConnection(endpoint, connection);
RawClient rawClient = new RawClient(controller, connectionFactory, new Segment("scope", "testHello", 0));
rawClient.sendRequest(1, new WireCommands.Hello(0, 0));
Mockito.verify(connection).send(new WireCommands.Hello(0, 0));
rawClient.close();
Mockito.verify(connection).close();
}
use of io.pravega.shared.protocol.netty.PravegaNodeUri in project pravega by pravega.
the class SegmentOutputStreamTest method testFailDurringFlush.
@Test(timeout = 10000)
public void testFailDurringFlush() throws ConnectionFailedException {
UUID cid = UUID.randomUUID();
PravegaNodeUri uri = new PravegaNodeUri("endpoint", SERVICE_PORT);
MockConnectionFactoryImpl cf = new MockConnectionFactoryImpl();
ScheduledExecutorService executor = mock(ScheduledExecutorService.class);
// Ensure task submitted to executor is run inline.
implementAsDirectExecutor(executor);
cf.setExecutor(executor);
MockController controller = new MockController(uri.getEndpoint(), uri.getPort(), cf);
ClientConnection connection = mock(ClientConnection.class);
cf.provideConnection(uri, connection);
InOrder order = Mockito.inOrder(connection);
SegmentOutputStreamImpl output = new SegmentOutputStreamImpl(SEGMENT, controller, cf, cid, segmentSealedCallback, RETRY_SCHEDULE, "");
output.reconnect();
order.verify(connection).send(new SetupAppend(1, cid, SEGMENT, ""));
cf.getProcessor(uri).appendSetup(new AppendSetup(1, SEGMENT, cid, 0));
ByteBuffer data = getBuffer("test");
CompletableFuture<Boolean> ack = new CompletableFuture<>();
output.write(new PendingEvent(null, data, ack));
order.verify(connection).send(new Append(SEGMENT, cid, 1, Unpooled.wrappedBuffer(data), null));
assertEquals(false, ack.isDone());
Mockito.doThrow(new ConnectionFailedException()).when(connection).send(new WireCommands.KeepAlive());
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
cf.getProcessor(uri).appendSetup(new AppendSetup(3, SEGMENT, cid, 1));
return null;
}
}).when(connection).send(new SetupAppend(3, cid, SEGMENT, ""));
Async.testBlocking(() -> {
output.flush();
}, () -> {
cf.getProcessor(uri).connectionDropped();
});
order.verify(connection).send(new SetupAppend(3, cid, SEGMENT, ""));
assertEquals(true, ack.isDone());
}
use of io.pravega.shared.protocol.netty.PravegaNodeUri in project pravega by pravega.
the class ControllerImplLBTest method testDiscoverySuccessUsingIPAddress.
@Test
public void testDiscoverySuccessUsingIPAddress() throws Exception {
final int serverPort1 = testRPCServer1.getPort();
final int serverPort2 = testRPCServer2.getPort();
// Use 2 servers to discover all the servers.
String localIP = InetAddress.getLoopbackAddress().getHostAddress();
@Cleanup("shutdown") InlineExecutor executor = new InlineExecutor();
final ControllerImpl controllerClient = new ControllerImpl(ControllerImplConfig.builder().clientConfig(ClientConfig.builder().controllerURI(URI.create("pravega://" + localIP + ":" + serverPort1 + "," + localIP + ":" + serverPort2)).build()).retryAttempts(1).build(), executor);
final Set<PravegaNodeUri> uris = fetchFromServers(controllerClient, 3);
// Verify we could reach all 3 controllers.
Assert.assertEquals(3, uris.size());
}
use of io.pravega.shared.protocol.netty.PravegaNodeUri in project pravega by pravega.
the class ControllerImplLBTest method testDirectSuccessUsingIPAddress.
@Test
public void testDirectSuccessUsingIPAddress() throws Exception {
final int serverPort1 = testRPCServer1.getPort();
final int serverPort2 = testRPCServer2.getPort();
final int serverPort3 = testRPCServer3.getPort();
// Directly use all 3 servers and verify.
String localIP = InetAddress.getLoopbackAddress().getHostAddress();
@Cleanup("shutdown") InlineExecutor executor = new InlineExecutor();
final ControllerImpl controllerClient = new ControllerImpl(ControllerImplConfig.builder().clientConfig(ClientConfig.builder().controllerURI(URI.create("tcp://" + localIP + ":" + serverPort1 + "," + localIP + ":" + serverPort2 + "," + localIP + ":" + serverPort3)).build()).retryAttempts(1).build(), executor);
final Set<PravegaNodeUri> uris = fetchFromServers(controllerClient, 3);
Assert.assertEquals(3, uris.size());
}
use of io.pravega.shared.protocol.netty.PravegaNodeUri in project pravega by pravega.
the class ControllerImplLBTest method testDiscoverySuccess.
@Test
public void testDiscoverySuccess() throws Exception {
final int serverPort1 = testRPCServer1.getPort();
final int serverPort2 = testRPCServer2.getPort();
// Use 2 servers to discover all the servers.
@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);
final Set<PravegaNodeUri> uris = fetchFromServers(controllerClient, 3);
// Verify we could reach all 3 controllers.
Assert.assertEquals(3, uris.size());
}
Aggregations