/** * Applies a delta to a wavelet container. */ public static void applyDeltaToWavelet(WaveletContainerImpl wavelet, WaveletDelta delta, long applicationTimestamp) throws InvalidProtocolBufferException, OperationException { ByteStringMessage<ProtocolAppliedWaveletDelta> appliedDelta = buildAppliedDelta(delta, applicationTimestamp); wavelet.applyDelta(appliedDelta, delta); } }
/** * Check that a container succeeds when adding non-existent participants and removing existing * participants. */ private void assertSuccessfulApplyWaveletOperations(WaveletContainerImpl with) throws Exception { WaveServerTestUtil.applyDeltaToWavelet(with, addParticipantDelta(with), 0L); assertEquals(with.accessSnapshot().getParticipants(), participants); WaveServerTestUtil.applyDeltaToWavelet(with, removeParticipantDelta(with), 0L); assertEquals(with.accessSnapshot().getParticipants(), Collections.emptySet()); }
/** * Check that a container succeeds when adding non-existent participants and removing existing * participants. */ private void assertSuccessfulApplyWaveletOperations(WaveletContainerImpl with) throws Exception { WaveServerTestUtil.applyDeltaToWavelet(with, addParticipantDelta(with), 0L); assertEquals(with.accessSnapshot().getParticipants(), participants); WaveServerTestUtil.applyDeltaToWavelet(with, removeParticipantDelta(with), 0L); assertEquals(with.accessSnapshot().getParticipants(), Collections.emptySet()); }
/** * Check that a container fails when removing non-existent participants and adding duplicate * participants, and that the partipant list is preserved correctly. */ private void assertFailedWaveletOperations(WaveletContainerImpl with) throws Exception { try { WaveServerTestUtil.applyDeltaToWavelet(with, removeParticipantDelta(with), 0L); fail("Should fail"); } catch (OperationException e) { // Correct } assertNull(localWavelet.accessSnapshot()); WaveServerTestUtil.applyDeltaToWavelet(with, addParticipantDelta(with), 0L); try { WaveServerTestUtil.applyDeltaToWavelet(with, addParticipantDelta(with), 0L); fail("Should fail"); } catch (OperationException e) { // Correct } assertEquals(with.accessSnapshot().getParticipants(), participants); try { WaveServerTestUtil.applyDeltaToWavelet(with, doubleRemoveParticipantDelta(with), 0L); fail("Should fail"); } catch (OperationException e) { // Correct } assertEquals(with.accessSnapshot().getParticipants(), participants); }
/** * Applies a delta to a wavelet container. */ public static void applyDeltaToWavelet(WaveletContainerImpl wavelet, WaveletDelta delta, long applicationTimestamp) throws InvalidProtocolBufferException, OperationException { ByteStringMessage<ProtocolAppliedWaveletDelta> appliedDelta = buildAppliedDelta(delta, applicationTimestamp); wavelet.applyDelta(appliedDelta, delta); } }
public void testOperationsOfDifferentSizes() throws Exception { String docId = "b+somedoc"; DocOp docOp1 = new DocOpBuilder().characters("hi").build(); WaveletDelta delta1 = createDelta(docId, docOp1, localVersion0); WaveServerTestUtil.applyDeltaToWavelet(localWavelet, delta1, 0L); try { DocOp docOp2 = new DocOpBuilder().characters("bye").build(); WaveletDelta delta2 = createDelta(docId, docOp2, localWavelet.getCurrentVersion()); WaveServerTestUtil.applyDeltaToWavelet(localWavelet, delta2, 0L); fail("Composition of \"hi\" and \"bye\" did not throw OperationException"); } catch (OperationException expected) { // Correct } }
/** * Creates a delta of no-ops and builds the corresponding applied and * transformed delta objects. */ private static WaveletDeltaRecord makeDelta(HashedVersion appliedAtVersion, long timestamp, int numOps) throws InvalidProtocolBufferException { // Use no-op delta so the ops can actually apply. WaveletDelta delta = UTIL.makeNoOpDelta(appliedAtVersion, timestamp, numOps); ByteStringMessage<ProtocolAppliedWaveletDelta> appliedDelta = WaveServerTestUtil.buildAppliedDelta(delta, timestamp); TransformedWaveletDelta transformedDelta = AppliedDeltaUtil.buildTransformedDelta(appliedDelta, delta); return new WaveletDeltaRecord(appliedAtVersion, appliedDelta, transformedDelta); } }
public void testOperationsOfDifferentSizes() throws Exception { String docId = "b+somedoc"; DocOp docOp1 = new DocOpBuilder().characters("hi").build(); WaveletDelta delta1 = createDelta(docId, docOp1, localVersion0); WaveServerTestUtil.applyDeltaToWavelet(localWavelet, delta1, 0L); try { DocOp docOp2 = new DocOpBuilder().characters("bye").build(); WaveletDelta delta2 = createDelta(docId, docOp2, localWavelet.getCurrentVersion()); WaveServerTestUtil.applyDeltaToWavelet(localWavelet, delta2, 0L); fail("Composition of \"hi\" and \"bye\" did not throw OperationException"); } catch (OperationException expected) { // Correct } }
/** * Creates a delta of no-ops and builds the corresponding applied and * transformed delta objects. */ private static WaveletDeltaRecord makeDelta(HashedVersion appliedAtVersion, long timestamp, int numOps) throws InvalidProtocolBufferException { // Use no-op delta so the ops can actually apply. WaveletDelta delta = UTIL.makeNoOpDelta(appliedAtVersion, timestamp, numOps); ByteStringMessage<ProtocolAppliedWaveletDelta> appliedDelta = WaveServerTestUtil.buildAppliedDelta(delta, timestamp); TransformedWaveletDelta transformedDelta = AppliedDeltaUtil.buildTransformedDelta(appliedDelta, delta); return new WaveletDeltaRecord(appliedAtVersion, appliedDelta, transformedDelta); } }
/** * Check that a container fails when removing non-existent participants and adding duplicate * participants, and that the partipant list is preserved correctly. */ private void assertFailedWaveletOperations(WaveletContainerImpl with) throws Exception { try { WaveServerTestUtil.applyDeltaToWavelet(with, removeParticipantDelta(with), 0L); fail("Should fail"); } catch (OperationException e) { // Correct } assertNull(localWavelet.accessSnapshot()); WaveServerTestUtil.applyDeltaToWavelet(with, addParticipantDelta(with), 0L); try { WaveServerTestUtil.applyDeltaToWavelet(with, addParticipantDelta(with), 0L); fail("Should fail"); } catch (OperationException e) { // Correct } assertEquals(with.accessSnapshot().getParticipants(), participants); try { WaveServerTestUtil.applyDeltaToWavelet(with, doubleRemoveParticipantDelta(with), 0L); fail("Should fail"); } catch (OperationException e) { // Correct } assertEquals(with.accessSnapshot().getParticipants(), participants); }