/** * Registers a listener on an operation channel that sucks out operations as * soon as they appear, sending them to a target sink. * * @param channel channel from which operations are to be pulled * @param sink sink to which operations are to be pushed */ public static void start(OperationChannel channel, FlushingOperationSink<WaveletOperation> sink) { channel.setListener(new OperationSucker(channel, sink)); }
public void testNoSuckingAfterShutdown() { sucker.shutdown(); sucker.onOperationReceived(); // Expect no interactions with the channel. }
@Override public void onOperationReceived() { if (!receptionIsPaused) { receiveLoop(); } }
@Override public void run() { sucker.shutdown(); } });
/** * Tests that the sucker doesn't touch the operation channel after being * shut down while consuming ops. */ public void testStopsSuckingAfterShutdown() { // Set expectations. WaveletOperation op = makeOp(); channel.expectPeek(op); sink.expectFlush(op, true); channel.expectPeek(op); channel.expectReceive(op); // Shut down the sucker when consuming the op. sink.expectConsume(op, new Runnable() { @Override public void run() { sucker.shutdown(); } }); // No more expectations of peek() or receive(). sucker.onOperationReceived(); }
@Override public void run() { sucker.shutdown(); } });
/** * Tests that the sucker doesn't touch the operation channel after being * shut down while consuming ops. */ public void testStopsSuckingAfterShutdown() { // Set expectations. WaveletOperation op = makeOp(); channel.expectPeek(op); sink.expectFlush(op, true); channel.expectPeek(op); channel.expectReceive(op); // Shut down the sucker when consuming the op. sink.expectConsume(op, new Runnable() { @Override public void run() { sucker.shutdown(); } }); // No more expectations of peek() or receive(). sucker.onOperationReceived(); }
public void testNoSuckingAfterShutdown() { sucker.shutdown(); sucker.onOperationReceived(); // Expect no interactions with the channel. }
@Override protected void setUp() throws Exception { super.setUp(); channel = new MockOperationChannel(); sink = new MockFlushingOperationSink(); sucker = new OperationSucker(channel, sink); }
/** * Fails this wavelet, removing listeners and notifying the wavelet's failure * handler that this wavelet is unusable. * * @param failure exception causing the failure */ private void fail(OperationException failure) { if (!failed) { failed = true; driver.shutdown(); ccBasedWaveListeners.clear(); // Currently this will cause the wave to disconnect. failureHandler.onWaveletFailed(failure); } }
/** * Tests that the sucker stops sucking if a flush is required, and * resumes when the flush is done. */ public void testFlushPausesSucking() { // Set expectations. WaveletOperation op = makeOp(); channel.expectPeek(op); sink.expectFlush(op, false); // Go! sucker.onOperationReceived(); channel.checkExpectationsSatisfied(); sink.checkExpectationsSatisfied(); Runnable resume = sink.getLastResumeCommand(); assertNotNull(resume); // Another op received should not cause any action sucker.onOperationReceived(); channel.checkExpectationsSatisfied(); sink.checkExpectationsSatisfied(); // Set expectations for the resume command. channel.expectPeek(op); sink.expectFlush(op, true); channel.expectPeek(op); channel.expectReceive(op); sink.expectConsume(op, null); channel.expectPeek(null); // Go! resume.run(); }
@Override protected void setUp() throws Exception { super.setUp(); channel = new MockOperationChannel(); sink = new MockFlushingOperationSink(); sucker = new OperationSucker(channel, sink); }
/** * Tests that the sucker keeps sucking while ops are available and the * sink doesn't need to flush. */ public void testSucksWhileNoFlushNeeded() { // Set expectations. WaveletOperation[] ops = makeOps(3); for (int i = 0; i < 3; ++i) { WaveletOperation op = ops[0]; channel.expectPeek(op); sink.expectFlush(op, true); // The sucker peeks again after flush in case the op has changed. channel.expectPeek(op); channel.expectReceive(op); sink.expectConsume(op, null); } channel.expectPeek(null); // Go! sucker.onOperationReceived(); }
CcBasedWavelet(WaveId waveId, WaveletOperationContext.Factory contextFactory, ParticipationHelper participationHelper, OperationChannel channel, ObservableWaveletData target, CcDocumentFactory<?> docFactory, FailureHandler failureHandler, DuplexOpSinkFactory opTaps) { this.docFactory = docFactory; this.channel = channel; this.failureHandler = failureHandler; Preconditions.checkNotNull(opTaps, "OpTaps cannot be null"); // Sink through which all operations are sent to remote state remote = new ChannelAdapter(channel); // Sink through which all operations are applied to local state applier = new OperationApplier(target, target.getWaveletId()); opTap = opTaps.create(target.getWaveletId(), applier, remote); // Create operation adapter, which translates semantic methods into // operations, applying them to the target as well as sending them down // the operation channel. Local operation failure fails this wavelet // permanently. wavelet = new OpBasedWavelet(waveId, target, contextFactory, participationHelper, opTap.incoming(), opTap.outgoing()); // Create operation sucker, which sucks operations out of the channel and // applies them to the CC target. driver = new OperationSucker(channel, opTap.incoming()); channel.setListener(driver); }
/** * Tests that the sucker keeps sucking while ops are available and the * sink doesn't need to flush. */ public void testSucksWhileNoFlushNeeded() { // Set expectations. WaveletOperation[] ops = makeOps(3); for (int i = 0; i < 3; ++i) { WaveletOperation op = ops[0]; channel.expectPeek(op); sink.expectFlush(op, true); // The sucker peeks again after flush in case the op has changed. channel.expectPeek(op); channel.expectReceive(op); sink.expectConsume(op, null); } channel.expectPeek(null); // Go! sucker.onOperationReceived(); }
/** * Tests that the sucker stops sucking if a flush is required, and * resumes when the flush is done. */ public void testFlushPausesSucking() { // Set expectations. WaveletOperation op = makeOp(); channel.expectPeek(op); sink.expectFlush(op, false); // Go! sucker.onOperationReceived(); channel.checkExpectationsSatisfied(); sink.checkExpectationsSatisfied(); Runnable resume = sink.getLastResumeCommand(); assertNotNull(resume); // Another op received should not cause any action sucker.onOperationReceived(); channel.checkExpectationsSatisfied(); sink.checkExpectationsSatisfied(); // Set expectations for the resume command. channel.expectPeek(op); sink.expectFlush(op, true); channel.expectPeek(op); channel.expectReceive(op); sink.expectConsume(op, null); channel.expectPeek(null); // Go! resume.run(); }