use of org.apache.cassandra.streaming.messages.StreamMessageHeader in project cassandra by apache.
the class CassandraEntireSSTableStreamWriterTest method testBlockReadingAndWritingOverWire.
@Test
public void testBlockReadingAndWritingOverWire() throws Throwable {
StreamSession session = setupStreamingSessionForTest();
InetAddressAndPort peer = FBUtilities.getBroadcastAddressAndPort();
// This is needed as Netty releases the ByteBuffers as soon as the channel is flushed
ByteBuf serializedFile = Unpooled.buffer(8192);
EmbeddedChannel channel = createMockNettyChannel(serializedFile);
try (AsyncStreamingOutputPlus out = new AsyncStreamingOutputPlus(channel);
ComponentContext context = ComponentContext.create(descriptor)) {
CassandraEntireSSTableStreamWriter writer = new CassandraEntireSSTableStreamWriter(sstable, session, context);
writer.write(out);
session.prepareReceiving(new StreamSummary(sstable.metadata().id, 1, 5104));
CassandraStreamHeader header = CassandraStreamHeader.builder().withSSTableFormat(sstable.descriptor.formatType).withSSTableVersion(sstable.descriptor.version).withSSTableLevel(0).withEstimatedKeys(sstable.estimatedKeys()).withSections(Collections.emptyList()).withSerializationHeader(sstable.header.toComponent()).withComponentManifest(context.manifest()).isEntireSSTable(true).withFirstKey(sstable.first).withTableId(sstable.metadata().id).build();
CassandraEntireSSTableStreamReader reader = new CassandraEntireSSTableStreamReader(new StreamMessageHeader(sstable.metadata().id, peer, session.planId(), false, 0, 0, 0, null), header, session);
SSTableMultiWriter sstableWriter = reader.read(new DataInputBuffer(serializedFile.nioBuffer(), false));
Collection<SSTableReader> newSstables = sstableWriter.finished();
assertEquals(1, newSstables.size());
}
}
use of org.apache.cassandra.streaming.messages.StreamMessageHeader in project cassandra by apache.
the class StreamingInboundHandlerTest method StreamDeserializingTask_deserialize_ISM_NoSession.
@Test(expected = IllegalStateException.class)
public void StreamDeserializingTask_deserialize_ISM_NoSession() throws IOException {
StreamMessageHeader header = new StreamMessageHeader(TableId.generate(), REMOTE_ADDR, UUID.randomUUID(), true, 0, 0, 0, UUID.randomUUID());
ByteBuffer temp = ByteBuffer.allocate(1024);
DataOutputPlus out = new DataOutputBuffer(temp);
StreamMessageHeader.serializer.serialize(header, out, MessagingService.current_version);
temp.flip();
DataInputPlus in = new DataInputBuffer(temp, false);
// session not found
IncomingStreamMessage.serializer.deserialize(in, MessagingService.current_version);
}
use of org.apache.cassandra.streaming.messages.StreamMessageHeader in project cassandra by apache.
the class StreamingInboundHandlerTest method StreamDeserializingTask_deserialize_ISM_HasSession.
@Test
public void StreamDeserializingTask_deserialize_ISM_HasSession() {
UUID planId = UUID.randomUUID();
StreamResultFuture future = StreamResultFuture.createFollower(0, planId, StreamOperation.REPAIR, REMOTE_ADDR, streamingChannel, streamingChannel.messagingVersion, UUID.randomUUID(), PreviewKind.ALL);
StreamManager.instance.registerFollower(future);
StreamMessageHeader header = new StreamMessageHeader(TableId.generate(), REMOTE_ADDR, planId, false, 0, 0, 0, UUID.randomUUID());
// IncomingStreamMessage.serializer.deserialize
StreamSession session = StreamManager.instance.findSession(header.sender, header.planId, header.sessionIndex, header.sendByFollower);
Assert.assertNotNull(session);
session = StreamManager.instance.findSession(header.sender, header.planId, header.sessionIndex, !header.sendByFollower);
Assert.assertNull(session);
}
use of org.apache.cassandra.streaming.messages.StreamMessageHeader in project cassandra by apache.
the class EntireSSTableStreamConcurrentComponentMutationTest method testStreamWithConcurrentComponentMutation.
private void testStreamWithConcurrentComponentMutation(Callable<?> runBeforeStreaming, Callable<?> runConcurrentWithStreaming) throws Throwable {
ByteBuf serializedFile = Unpooled.buffer(8192);
InetAddressAndPort peer = FBUtilities.getBroadcastAddressAndPort();
StreamSession session = setupStreamingSessionForTest();
Collection<OutgoingStream> outgoingStreams = store.getStreamManager().createOutgoingStreams(session, rangesAtEndpoint, NO_PENDING_REPAIR, PreviewKind.NONE);
CassandraOutgoingFile outgoingFile = (CassandraOutgoingFile) Iterables.getOnlyElement(outgoingStreams);
Future<?> streaming = executeAsync(() -> {
runBeforeStreaming.call();
try (AsyncStreamingOutputPlus out = new AsyncStreamingOutputPlus(createMockNettyChannel(serializedFile))) {
outgoingFile.write(session, out, MessagingService.current_version);
assertTrue(sstable.descriptor.getTemporaryFiles().isEmpty());
}
return null;
});
Future<?> concurrentMutations = executeAsync(runConcurrentWithStreaming);
streaming.get(3, TimeUnit.MINUTES);
concurrentMutations.get(3, TimeUnit.MINUTES);
session.prepareReceiving(new StreamSummary(sstable.metadata().id, 1, 5104));
StreamMessageHeader messageHeader = new StreamMessageHeader(sstable.metadata().id, peer, session.planId(), false, 0, 0, 0, null);
try (DataInputBuffer in = new DataInputBuffer(serializedFile.nioBuffer(), false)) {
CassandraStreamHeader header = CassandraStreamHeader.serializer.deserialize(in, MessagingService.current_version);
CassandraEntireSSTableStreamReader reader = new CassandraEntireSSTableStreamReader(messageHeader, header, session);
SSTableReader streamedSSTable = Iterables.getOnlyElement(reader.read(in).finished());
SSTableUtils.assertContentEquals(sstable, streamedSSTable);
}
}
Aggregations