use of io.pravega.shared.protocol.netty.PravegaNodeUri in project pravega by pravega.
the class ConditionalOutputStreamTest method testNonExpiryTokenCheckFailure.
@Test(timeout = 10000)
public void testNonExpiryTokenCheckFailure() throws ConnectionFailedException {
@Cleanup MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
@Cleanup MockController controller = new MockController("localhost", 0, connectionFactory, true);
ConditionalOutputStreamFactory factory = new ConditionalOutputStreamFactoryImpl(controller, connectionFactory);
Segment segment = new Segment("scope", "testWrite", 1);
@Cleanup ConditionalOutputStream objectUnderTest = factory.createConditionalOutputStream(segment, DelegationTokenProviderFactory.create("token", controller, segment, AccessOperation.ANY), EventWriterConfig.builder().build());
ByteBuffer data = ByteBuffer.allocate(10);
ClientConnection clientConnection = Mockito.mock(ClientConnection.class);
PravegaNodeUri location = new PravegaNodeUri("localhost", 0);
connectionFactory.provideConnection(location, clientConnection);
setupAppend(connectionFactory, segment, clientConnection, location);
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
ConditionalAppend argument = (ConditionalAppend) invocation.getArgument(0);
ReplyProcessor processor = connectionFactory.getProcessor(location);
processor.process(new WireCommands.AuthTokenCheckFailed(argument.getRequestId(), "SomeException", WireCommands.AuthTokenCheckFailed.ErrorCode.TOKEN_CHECK_FAILED));
return null;
}
}).when(clientConnection).send(any(ConditionalAppend.class));
AssertExtensions.assertThrows(AuthenticationException.class, () -> objectUnderTest.write(data, 0));
}
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, true);
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(Mockito.eq(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 RawClientTest method testOverloadConstructor.
@Test
public void testOverloadConstructor() throws ConnectionFailedException {
PravegaNodeUri endpoint = new PravegaNodeUri("localhost", -1);
@Cleanup MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
ClientConnection connection = Mockito.mock(ClientConnection.class);
connectionFactory.provideConnection(endpoint, connection);
RawClient rawClient = new RawClient(endpoint, connectionFactory);
rawClient.sendRequest(1, new WireCommands.Hello(0, 0));
Mockito.verify(connection).send(Mockito.eq(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 RawClientTest method testReplyWithoutRequest.
@Test
public void testReplyWithoutRequest() {
PravegaNodeUri endpoint = new PravegaNodeUri("localhost", -1);
@Cleanup MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
@Cleanup MockController controller = new MockController(endpoint.getEndpoint(), endpoint.getPort(), connectionFactory, true);
ClientConnection connection = Mockito.mock(ClientConnection.class);
connectionFactory.provideConnection(endpoint, connection);
@Cleanup RawClient rawClient = new RawClient(controller, connectionFactory, new Segment("scope", "testHello", 0));
UUID id = UUID.randomUUID();
ReplyProcessor processor = connectionFactory.getProcessor(endpoint);
DataAppended reply = new DataAppended(requestId, id, 1, 0, -1);
processor.process(reply);
assertFalse(rawClient.isClosed());
}
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());
}
Aggregations