@Override public void createSegment(CreateSegment createStreamSegment) { Timer timer = new Timer(); final String operation = "createSegment"; Collection<AttributeUpdate> attributes = Arrays.asList( new AttributeUpdate(SCALE_POLICY_TYPE, AttributeUpdateType.Replace, ((Byte) createStreamSegment.getScaleType()).longValue()), new AttributeUpdate(SCALE_POLICY_RATE, AttributeUpdateType.Replace, ((Integer) createStreamSegment.getTargetRate()).longValue()), new AttributeUpdate(CREATION_TIME, AttributeUpdateType.None, System.currentTimeMillis()) ); if (!verifyToken(createStreamSegment.getSegment(), createStreamSegment.getRequestId(), createStreamSegment.getDelegationToken(), operation)) { return; } log.info(createStreamSegment.getRequestId(), "Creating stream segment {}.", createStreamSegment); segmentStore.createStreamSegment(createStreamSegment.getSegment(), attributes, TIMEOUT) .thenAccept(v -> { this.createStreamSegment.reportSuccessEvent(timer.getElapsed()); connection.send(new SegmentCreated(createStreamSegment.getRequestId(), createStreamSegment.getSegment())); }) .whenComplete((res, e) -> { if (e == null) { if (statsRecorder != null) { statsRecorder.createSegment(createStreamSegment.getSegment(), createStreamSegment.getScaleType(), createStreamSegment.getTargetRate()); } } else { this.createStreamSegment.reportFailEvent(timer.getElapsed()); handleException(createStreamSegment.getRequestId(), createStreamSegment.getSegment(), operation, e); } }); }
@Override public Void answer(InvocationOnMock invocation) throws Throwable { CreateSegment request = (CreateSegment) invocation.getArgument(0); connectionFactory.getProcessor(endpoint) .process(new SegmentCreated(request.getRequestId(), request.getSegment())); return null; } }).when(connection).sendAsync(Mockito.any(CreateSegment.class),
@Override public Void answer(InvocationOnMock invocation) throws Throwable { WireCommands.CreateSegment request = (WireCommands.CreateSegment) invocation.getArgument(0); connectionFactory.getProcessor(location) .process(new WireCommands.SegmentCreated(request.getRequestId(), request.getSegment())); return null; } }).when(connection).sendAsync(Mockito.any(WireCommands.CreateSegment.class),
@Override public Void answer(InvocationOnMock invocation) throws Throwable { CreateSegment request = (CreateSegment) invocation.getArgument(0); connectionFactory.getProcessor(location) .process(new SegmentCreated(request.getRequestId(), request.getSegment())); return null; } }).when(connection).sendAsync(Mockito.any(CreateSegment.class),
@Override public Void answer(InvocationOnMock invocation) throws Throwable { CreateSegment request = (CreateSegment) invocation.getArgument(0); connectionFactory.getProcessor(endpoint) .process(new SegmentCreated(request.getRequestId(), request.getSegment())); return null; } }).when(connection).sendAsync(Mockito.any(CreateSegment.class),
@Override public Void answer(InvocationOnMock invocation) throws Throwable { CreateSegment request = (CreateSegment) invocation.getArgument(0); connectionFactory.getProcessor(location) .process(new SegmentCreated(request.getRequestId(), request.getSegment())); return null; } }).when(connection).sendAsync(Mockito.any(CreateSegment.class),