use of io.pravega.segmentstore.contracts.StreamSegmentStore in project pravega by pravega.
the class AppendProcessorAuthFailedTest method setUp.
@Before
public void setUp() throws Exception {
StreamSegmentStore store = mock(StreamSegmentStore.class);
connection = mock(ServerConnection.class);
processor = new AppendProcessor(store, connection, new FailingRequestProcessor(), (resource, token, expectedLevel) -> false);
}
use of io.pravega.segmentstore.contracts.StreamSegmentStore in project pravega by pravega.
the class AppendProcessorTest method testInvalidOffset.
@Test
public void testInvalidOffset() {
String streamSegmentName = "testAppendSegment";
UUID clientId = UUID.randomUUID();
byte[] data = new byte[] { 1, 2, 3, 4, 6, 7, 8, 9 };
StreamSegmentStore store = mock(StreamSegmentStore.class);
ServerConnection connection = mock(ServerConnection.class);
AppendProcessor processor = new AppendProcessor(store, connection, new FailingRequestProcessor(), null);
setupGetStreamSegmentInfo(streamSegmentName, clientId, 100, store);
processor.setupAppend(new SetupAppend(1, clientId, streamSegmentName, ""));
try {
processor.append(new Append(streamSegmentName, clientId, data.length, Unpooled.wrappedBuffer(data), null));
fail();
} catch (RuntimeException e) {
// expected
}
verify(store).getStreamSegmentInfo(anyString(), eq(true), eq(AppendProcessor.TIMEOUT));
verify(connection).send(new AppendSetup(1, streamSegmentName, clientId, 100));
verify(connection, atLeast(0)).resumeReading();
verifyNoMoreInteractions(connection);
verifyNoMoreInteractions(store);
}
use of io.pravega.segmentstore.contracts.StreamSegmentStore in project pravega by pravega.
the class AppendProcessorTest method testAppendFails.
@Test
public void testAppendFails() {
String streamSegmentName = "testAppendSegment";
UUID clientId = UUID.randomUUID();
byte[] data = new byte[] { 1, 2, 3, 4, 6, 7, 8, 9 };
StreamSegmentStore store = mock(StreamSegmentStore.class);
ServerConnection connection = mock(ServerConnection.class);
AppendProcessor processor = new AppendProcessor(store, connection, new FailingRequestProcessor(), null);
setupGetStreamSegmentInfo(streamSegmentName, clientId, store);
CompletableFuture<Void> result = new CompletableFuture<>();
result.completeExceptionally(new RuntimeException("Fake exception for testing"));
when(store.append(streamSegmentName, data, updateEventNumber(clientId, data.length), AppendProcessor.TIMEOUT)).thenReturn(result);
processor.setupAppend(new SetupAppend(1, clientId, streamSegmentName, ""));
processor.append(new Append(streamSegmentName, clientId, data.length, Unpooled.wrappedBuffer(data), null));
try {
processor.append(new Append(streamSegmentName, clientId, data.length * 2, Unpooled.wrappedBuffer(data), null));
fail();
} catch (IllegalStateException e) {
// Expected
}
verify(connection).send(new AppendSetup(1, streamSegmentName, clientId, 0));
verify(connection, atLeast(0)).resumeReading();
verify(connection).close();
verify(store, atMost(1)).append(any(), any(), any(), any());
verifyNoMoreInteractions(connection);
}
use of io.pravega.segmentstore.contracts.StreamSegmentStore in project pravega by pravega.
the class AppendProcessorTest method testEventNumbers.
@Test
public void testEventNumbers() {
String streamSegmentName = "testAppendSegment";
UUID clientId = UUID.randomUUID();
byte[] data = new byte[] { 1, 2, 3, 4, 6, 7, 8, 9 };
StreamSegmentStore store = mock(StreamSegmentStore.class);
ServerConnection connection = mock(ServerConnection.class);
AppendProcessor processor = new AppendProcessor(store, connection, new FailingRequestProcessor(), null);
CompletableFuture<SegmentProperties> propsFuture = CompletableFuture.completedFuture(StreamSegmentInformation.builder().name(streamSegmentName).build());
when(store.getStreamSegmentInfo(streamSegmentName, true, AppendProcessor.TIMEOUT)).thenReturn(propsFuture);
processor.setupAppend(new SetupAppend(1, clientId, streamSegmentName, ""));
verify(store).getStreamSegmentInfo(streamSegmentName, true, AppendProcessor.TIMEOUT);
CompletableFuture<Void> result = CompletableFuture.completedFuture(null);
int eventCount = 100;
when(store.append(streamSegmentName, data, updateEventNumber(clientId, 100, SegmentMetadata.NULL_ATTRIBUTE_VALUE, eventCount), AppendProcessor.TIMEOUT)).thenReturn(result);
processor.append(new Append(streamSegmentName, clientId, 100, eventCount, Unpooled.wrappedBuffer(data), null));
verify(store).append(streamSegmentName, data, updateEventNumber(clientId, 100, SegmentMetadata.NULL_ATTRIBUTE_VALUE, eventCount), AppendProcessor.TIMEOUT);
Map<UUID, Long> map = new HashMap<>();
map.put(clientId, 100L);
map.put(EVENT_COUNT, 100L);
propsFuture = CompletableFuture.completedFuture(StreamSegmentInformation.builder().name(streamSegmentName).attributes(map).build());
when(store.append(streamSegmentName, data, updateEventNumber(clientId, 200, 100, eventCount), AppendProcessor.TIMEOUT)).thenReturn(result);
processor.append(new Append(streamSegmentName, clientId, 200, eventCount, Unpooled.wrappedBuffer(data), null));
verify(store).append(streamSegmentName, data, updateEventNumber(clientId, 200, 100, eventCount), AppendProcessor.TIMEOUT);
verifyNoMoreInteractions(store);
}
use of io.pravega.segmentstore.contracts.StreamSegmentStore in project pravega by pravega.
the class AppendProcessorTest method testEventNumbersOldClient.
@Test
public void testEventNumbersOldClient() {
String streamSegmentName = "testAppendSegment";
UUID clientId = UUID.randomUUID();
byte[] data = new byte[] { 1, 2, 3, 4, 6, 7, 8, 9 };
StreamSegmentStore store = mock(StreamSegmentStore.class);
ServerConnection connection = mock(ServerConnection.class);
AppendProcessor processor = new AppendProcessor(store, connection, new FailingRequestProcessor(), null);
CompletableFuture<SegmentProperties> propsFuture = CompletableFuture.completedFuture(StreamSegmentInformation.builder().name(streamSegmentName).attributes(Collections.singletonMap(clientId, 100L)).build());
when(store.getStreamSegmentInfo(streamSegmentName, true, AppendProcessor.TIMEOUT)).thenReturn(propsFuture);
processor.setupAppend(new SetupAppend(1, clientId, streamSegmentName, ""));
verify(store).getStreamSegmentInfo(streamSegmentName, true, AppendProcessor.TIMEOUT);
int eventCount = 10;
CompletableFuture<Void> result = CompletableFuture.completedFuture(null);
when(store.append(streamSegmentName, data, updateEventNumber(clientId, 200, 100, eventCount), AppendProcessor.TIMEOUT)).thenReturn(result);
processor.append(new Append(streamSegmentName, clientId, 200, eventCount, Unpooled.wrappedBuffer(data), null));
verify(store).append(streamSegmentName, data, updateEventNumber(clientId, 200, 100, eventCount), AppendProcessor.TIMEOUT);
when(store.append(streamSegmentName, data, updateEventNumber(clientId, 300, 200, eventCount), AppendProcessor.TIMEOUT)).thenReturn(result);
processor.append(new Append(streamSegmentName, clientId, 300, eventCount, Unpooled.wrappedBuffer(data), null));
verify(store).append(streamSegmentName, data, updateEventNumber(clientId, 300, 200, eventCount), AppendProcessor.TIMEOUT);
verifyNoMoreInteractions(store);
}
Aggregations