}, connectionFactory.getInternalExecutor()).thenComposeAsync(connection -> { CompletableFuture<Void> connectionSetupFuture = state.newConnection(connection); SetupAppend cmd = new SetupAppend(requestIdGenerator.get(), writerId, segmentName, delegationToken); try { connection.send(cmd);
String newSegment = setupAppend.getSegment(); UUID writer = setupAppend.getWriterId(); log.info("Setting up appends for writer: {} on segment: {}", writer, newSegment); if (this.tokenVerifier != null && !tokenVerifier.verifyToken(newSegment, setupAppend.getDelegationToken(), AuthHandler.Permissions.READ_UPDATE)) { log.warn("Delegation token verification failed"); handleException(setupAppend.getWriterId(), setupAppend.getRequestId(), newSegment, "Update Segment Attribute", new AuthenticationException("Token verification failed")); return; try { if (u != null) { handleException(writer, setupAppend.getRequestId(), newSegment, "setting up append", u); } else { long eventNumber = attributes.getOrDefault(writer, Attributes.NULL_ATTRIBUTE_VALUE); latestEventNumbers.putIfAbsent(Pair.of(newSegment, writer), eventNumber); connection.send(new AppendSetup(setupAppend.getRequestId(), newSegment, writer, eventNumber)); handleException(writer, setupAppend.getRequestId(), newSegment, "handling setupAppend result", e);
case SETUP_APPEND: WireCommands.SetupAppend append = (WireCommands.SetupAppend) command; appendingSegments.put(append.getWriterId(), new Segment(append.getSegment())); result = append; break;
writeMessage((SetupAppend) msg, out); SetupAppend setup = (SetupAppend) msg; setupSegments.put(setup.getSegment(), new Session(setup.getWriterId())); } else if (msg instanceof Flush) { Flush flush = (Flush) msg;
output.reconnect(); InOrder inOrder = Mockito.inOrder(connection); inOrder.verify(connection).send(new SetupAppend(1, cid, SEGMENT, "")); cf.getProcessor(uri).appendSetup(new AppendSetup(1, SEGMENT, cid, 0)); ByteBuffer data = getBuffer("test"); cf.getProcessor(uri).appendSetup(new AppendSetup(2, SEGMENT, cid, 0)); inOrder.verify(connection).send(new WireCommands.KeepAlive()); inOrder.verify(connection).send(new SetupAppend(2, cid, SEGMENT, "")); inOrder.verify(connection).sendAsync(Mockito.eq(Collections.singletonList(append)), Mockito.any()); cf.getProcessor(uri).dataAppended(new WireCommands.DataAppended(cid, 1, 0));
.thenReturn(CompletableFuture.completedFuture(Collections.emptyMap())); processor.setupAppend(new SetupAppend(1, clientId, streamSegmentName, "")); verify(store).getAttributes(streamSegmentName, Collections.singleton(clientId), true, AppendProcessor.TIMEOUT);
return null; }).when(connection).send(new SetupAppend(2, cid, SEGMENT, "")); Append append3 = new Append(SEGMENT, cid, 3, 1, Unpooled.wrappedBuffer(getBuffer("test3")), null); Append append4 = new Append(SEGMENT, cid, 4, 1, Unpooled.wrappedBuffer(getBuffer("test4")), null); inOrder.verify(connection).send(new SetupAppend(1, cid, SEGMENT, "")); inOrder.verify(connection).send(append1); inOrder.verify(connection).send(append2); inOrder.verify(connection).close(); inOrder.verify(connection).send(new SetupAppend(2, cid, SEGMENT, "")); inOrder.verify(connection).sendAsync(eq(ImmutableList.of(append1, append2)), any()); inOrder.verify(connection).close(); inOrder.verify(connection).send(new SetupAppend(3, cid, SEGMENT, "")); inOrder.verify(connection).sendAsync(eq(ImmutableList.of(append1, append2)), any()); inOrder.verify(connection).send(append3);
.thenReturn(result); processor.setupAppend(new SetupAppend(1, clientId1, segment1, "")); processor.append(new Append(segment1, clientId1, data.length, 1, Unpooled.wrappedBuffer(data), null)); processor.setupAppend(new SetupAppend(2, clientId2, segment2, "")); processor.append(new Append(segment2, clientId2, data.length, 1, Unpooled.wrappedBuffer(data), null));
output.reconnect(); InOrder inOrder = Mockito.inOrder(connection); inOrder.verify(connection).send(new SetupAppend(1, cid, SEGMENT, "")); cf.getProcessor(uri).appendSetup(new AppendSetup(1, SEGMENT, cid, 0)); ByteBuffer data = getBuffer("test"); }); inOrder.verify(connection).send(append); inOrder.verify(connection).send(new SetupAppend(2, cid, SEGMENT, "")); inOrder.verify(connection).sendAsync(Mockito.eq(Collections.singletonList(append)), Mockito.any()); inOrder.verify(connection).send(append2);
when(store.append(streamSegmentName, data, updateEventNumber(clientId, 1), AppendProcessor.TIMEOUT)).thenReturn(result); processor.setupAppend(new SetupAppend(1, clientId, streamSegmentName, "")); processor.append(new Append(streamSegmentName, clientId, 1, 1, Unpooled.wrappedBuffer(data), null));
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");
when(store.append(streamSegmentName, data, updateEventNumber(clientId, 1), AppendProcessor.TIMEOUT)).thenReturn(result); processor.setupAppend(new SetupAppend(1, clientId, streamSegmentName, "")); processor.append(new Append(streamSegmentName, clientId, 1, 1, Unpooled.wrappedBuffer(data), null));
processor.setupAppend(new SetupAppend(1, clientId, streamSegmentName1, "")); verifier.verify(store).getAttributes(anyString(), eq(Collections.singleton(clientId)), eq(true), eq(AppendProcessor.TIMEOUT)); processor.setupAppend(new SetupAppend(1, clientId, streamSegmentName2, "")); verifier.verify(store).getAttributes(anyString(), eq(Collections.singleton(clientId)), eq(true), eq(AppendProcessor.TIMEOUT));
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"); return null; }).when(connection).send(new SetupAppend(3, cid, SEGMENT, "")); AssertExtensions.assertBlocks(() -> { output.flush(); cf.getProcessor(uri).connectionDropped(); }); order.verify(connection).send(new SetupAppend(3, cid, SEGMENT, "")); assertEquals(true, ack.isDone());
SegmentOutputStreamImpl output = new SegmentOutputStreamImpl(SEGMENT, controller, cf, cid, exceptionCallback, RETRY_SCHEDULE, ""); output.reconnect(); verify(connection).send(new SetupAppend(1, cid, SEGMENT, "")); cf.getProcessor(uri).appendSetup(new AppendSetup(1, SEGMENT, cid, 0)); ByteBuffer data = getBuffer("test"); return null; }).when(connection).send(new SetupAppend(3, cid, SEGMENT, "")); AssertExtensions.assertBlocks(() -> { AssertExtensions.assertThrows(SegmentSealedException.class, () -> output.flush());
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");
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");
Append append3 = new Append(SEGMENT, cid, 3, 1, Unpooled.wrappedBuffer(getBuffer("test3")), null); Append append4 = new Append(SEGMENT, cid, 4, 1, Unpooled.wrappedBuffer(getBuffer("test4")), null); inOrder.verify(connection).send(new SetupAppend(1, cid, SEGMENT, "")); inOrder.verify(connection).send(append1); inOrder.verify(connection).send(append2); inOrder.verify(connection).close(); inOrder.verify(connection).send(new SetupAppend(2, cid, SEGMENT, "")); inOrder.verify(connection).sendAsync(eq(ImmutableList.of(append1, append2)), any()); inOrder.verify(connection).send(append3);
order.verify(connection).send(new SetupAppend(1, cid, TXN_SEGMENT, "")); cf.getProcessor(uri).appendSetup(new AppendSetup(1, TXN_SEGMENT, cid, 0)); ByteBuffer data = getBuffer("test");
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");