use of io.pravega.client.connection.impl.ClientConnection in project pravega by pravega.
the class AsyncSegmentInputStreamTest method testCloseAbortsRead.
@Test(timeout = 10000)
public void testCloseAbortsRead() throws InterruptedException, ExecutionException {
Segment segment = new Segment("scope", "testRetry", 4);
PravegaNodeUri endpoint = new PravegaNodeUri("localhost", SERVICE_PORT);
@Cleanup MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
@Cleanup MockController controller = new MockController(endpoint.getEndpoint(), endpoint.getPort(), connectionFactory, true);
Semaphore dataAvailable = new Semaphore(0);
@Cleanup AsyncSegmentInputStreamImpl in = new AsyncSegmentInputStreamImpl(controller, connectionFactory, segment, DelegationTokenProviderFactory.createWithEmptyToken(), dataAvailable);
ClientConnection c = mock(ClientConnection.class);
connectionFactory.provideConnection(endpoint, c);
// Make sure connection is established.
in.getConnection().get();
CompletableFuture<SegmentRead> read = in.read(1234, 5678);
assertFalse(read.isDone());
in.close();
assertThrows(ConnectionClosedException.class, () -> Futures.getThrowingException(read));
verify(c).close();
assertEquals(0, dataAvailable.availablePermits());
}
use of io.pravega.client.connection.impl.ClientConnection in project pravega by pravega.
the class AsyncSegmentInputStreamTest method testRead.
@Test(timeout = 10000)
public void testRead() throws ConnectionFailedException {
Segment segment = new Segment("scope", "testRead", 1);
PravegaNodeUri endpoint = new PravegaNodeUri("localhost", SERVICE_PORT);
@Cleanup MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
@Cleanup MockController controller = new MockController(endpoint.getEndpoint(), endpoint.getPort(), connectionFactory, true);
Semaphore dataAvailable = new Semaphore(0);
@Cleanup AsyncSegmentInputStreamImpl in = new AsyncSegmentInputStreamImpl(controller, connectionFactory, segment, DelegationTokenProviderFactory.createWithEmptyToken(), dataAvailable);
ClientConnection c = mock(ClientConnection.class);
connectionFactory.provideConnection(endpoint, c);
WireCommands.SegmentRead segmentRead = new WireCommands.SegmentRead(segment.getScopedName(), 1234, false, false, Unpooled.EMPTY_BUFFER, in.getRequestId());
CompletableFuture<SegmentRead> readFuture = in.read(1234, 5678);
assertEquals(0, dataAvailable.availablePermits());
AssertExtensions.assertBlocks(() -> readFuture.get(), () -> {
ReplyProcessor processor = connectionFactory.getProcessor(endpoint);
processor.process(segmentRead);
});
assertEquals(1, dataAvailable.availablePermits());
verify(c).send(eq(new WireCommands.ReadSegment(segment.getScopedName(), 1234, 5678, "", in.getRequestId())));
assertTrue(Futures.isSuccessful(readFuture));
assertEquals(segmentRead, readFuture.join());
verifyNoMoreInteractions(c);
}
use of io.pravega.client.connection.impl.ClientConnection in project pravega by pravega.
the class AsyncSegmentInputStreamTest method testWrongOffsetReturned.
@Test(timeout = 10000)
public void testWrongOffsetReturned() throws ConnectionFailedException {
Segment segment = new Segment("scope", "testWrongOffsetReturned", 0);
byte[] good = new byte[] { 0, 1, 2, 3, 4 };
byte[] bad = new byte[] { 9, 8, 7, 6 };
PravegaNodeUri endpoint = new PravegaNodeUri("localhost", SERVICE_PORT);
@Cleanup MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
@Cleanup MockController controller = new MockController(endpoint.getEndpoint(), endpoint.getPort(), connectionFactory, true);
Semaphore dataAvailable = new Semaphore(0);
@Cleanup AsyncSegmentInputStreamImpl in = new AsyncSegmentInputStreamImpl(controller, connectionFactory, segment, DelegationTokenProviderFactory.createWithEmptyToken(), dataAvailable);
ClientConnection c = mock(ClientConnection.class);
connectionFactory.provideConnection(endpoint, c);
CompletableFuture<SegmentRead> readFuture = in.read(1234, 5678);
assertEquals(0, dataAvailable.availablePermits());
AssertExtensions.assertBlocks(() -> readFuture.get(), () -> {
ReplyProcessor processor = connectionFactory.getProcessor(endpoint);
processor.process(new WireCommands.SegmentRead(segment.getScopedName(), 1235, false, false, Unpooled.wrappedBuffer(bad), in.getRequestId()));
processor.process(new WireCommands.SegmentRead(segment.getScopedName(), 1234, false, false, Unpooled.wrappedBuffer(good), in.getRequestId()));
});
assertEquals(2, dataAvailable.availablePermits());
verify(c).send(eq(new WireCommands.ReadSegment(segment.getScopedName(), 1234, 5678, "", in.getRequestId())));
assertTrue(Futures.isSuccessful(readFuture));
assertEquals(Unpooled.wrappedBuffer(good), readFuture.join().getData());
verifyNoMoreInteractions(c);
}
use of io.pravega.client.connection.impl.ClientConnection in project pravega by pravega.
the class AsyncSegmentInputStreamTest method testRecvErrorMessage.
@Test
public void testRecvErrorMessage() throws ExecutionException, InterruptedException {
int requestId = 0;
Segment segment = new Segment("scope", "testWrongOffsetReturned", requestId);
PravegaNodeUri endpoint = new PravegaNodeUri("localhost", SERVICE_PORT);
@Cleanup MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
@Cleanup MockController controller = new MockController(endpoint.getEndpoint(), endpoint.getPort(), connectionFactory, true);
Semaphore dataAvailable = new Semaphore(requestId);
@Cleanup AsyncSegmentInputStreamImpl in = new AsyncSegmentInputStreamImpl(controller, connectionFactory, segment, DelegationTokenProviderFactory.createWithEmptyToken(), dataAvailable);
ClientConnection c = mock(ClientConnection.class);
connectionFactory.provideConnection(endpoint, c);
in.getConnection().get();
ReplyProcessor processor = connectionFactory.getProcessor(endpoint);
WireCommands.ErrorMessage reply = new WireCommands.ErrorMessage(requestId, segment.getScopedName(), "error.", WireCommands.ErrorMessage.ErrorCode.ILLEGAL_ARGUMENT_EXCEPTION);
processor.process(reply);
verify(c).close();
}
use of io.pravega.client.connection.impl.ClientConnection in project pravega by pravega.
the class AsyncSegmentInputStreamTest method testSegmentTruncated.
@Test(timeout = 10000)
public void testSegmentTruncated() throws ConnectionFailedException {
String mockClientReplyStackTrace = "SomeException";
Segment segment = new Segment("scope", "testRead", 1);
PravegaNodeUri endpoint = new PravegaNodeUri("localhost", SERVICE_PORT);
@Cleanup MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
@Cleanup MockController controller = new MockController(endpoint.getEndpoint(), endpoint.getPort(), connectionFactory, true);
Semaphore dataAvailable = new Semaphore(0);
@Cleanup AsyncSegmentInputStreamImpl in = new AsyncSegmentInputStreamImpl(controller, connectionFactory, segment, DelegationTokenProviderFactory.createWithEmptyToken(), dataAvailable);
ClientConnection c = mock(ClientConnection.class);
connectionFactory.provideConnection(endpoint, c);
// segment truncated response from Segment store.
WireCommands.SegmentIsTruncated segmentIsTruncated = new WireCommands.SegmentIsTruncated(in.getRequestId(), segment.getScopedName(), 1234, mockClientReplyStackTrace, 1234L);
// Trigger read.
CompletableFuture<SegmentRead> readFuture = in.read(1234, 5678);
assertEquals(0, dataAvailable.availablePermits());
// verify that a response from Segment store completes the readFuture and the future completes with SegmentTruncatedException.
AssertExtensions.assertBlocks(() -> assertThrows(SegmentTruncatedException.class, () -> readFuture.get()), () -> {
ReplyProcessor processor = connectionFactory.getProcessor(endpoint);
processor.process(segmentIsTruncated);
});
verify(c).send(eq(new WireCommands.ReadSegment(segment.getScopedName(), 1234, 5678, "", in.getRequestId())));
// verify read future completedExceptionally
assertTrue(!Futures.isSuccessful(readFuture));
assertThrows(SegmentTruncatedException.class, () -> readFuture.get());
verifyNoMoreInteractions(c);
// Ensure that reads at a different offset can still happen on the same instance.
WireCommands.SegmentRead segmentRead = new WireCommands.SegmentRead(segment.getScopedName(), 5656, false, false, Unpooled.EMPTY_BUFFER, in.getRequestId());
CompletableFuture<SegmentRead> readFuture2 = in.read(5656, 5678);
AssertExtensions.assertBlocks(() -> readFuture2.get(), () -> {
ReplyProcessor processor = connectionFactory.getProcessor(endpoint);
processor.segmentRead(segmentRead);
});
verify(c).send(eq(new WireCommands.ReadSegment(segment.getScopedName(), 5656, 5678, "", in.getRequestId())));
assertTrue(Futures.isSuccessful(readFuture2));
assertEquals(segmentRead, readFuture2.join());
verifyNoMoreInteractions(c);
assertEquals(1, dataAvailable.availablePermits());
}
Aggregations