@Override public WaveletDeltaRecord submitRequest(WaveletName waveletName, ProtocolSignedDelta signedDelta) throws OperationException, InvalidProtocolBufferException, InvalidHashException, PersistenceException, WaveletStateException { awaitLoad(); acquireWriteLock(); try { checkStateOk(); HashedVersion before = getCurrentVersion(); WaveletDeltaRecord result = transformAndApplyLocalDelta(signedDelta); HashedVersion after = getCurrentVersion(); // Only publish and persist the delta if it wasn't transformed away // (right now it never is since the current OT algorithm doesn't transform ops away) // and wasn't a duplicate of a previously applied delta. if (!after.equals(before)) { Preconditions.checkState(!result.isEmpty()); Preconditions.checkState(result.getAppliedAtVersion().equals(before)); ImmutableSet<String> domainsToNotify = domainsOf(Iterables.concat( accessSnapshot().getParticipants(), participantsRemovedBy(result.getTransformedDelta()))); notifyOfDeltas(ImmutableList.of(result), domainsToNotify); // We always persist a local delta immediately after it's applied // and after it's broadcast on the wave bus and to remote servers. persist(result.getResultingVersion(), domainsToNotify); } return result; } finally { releaseWriteLock(); } }
/** * Tests that duplicate operations are a no-op. * * @throws Exception should not be thrown. */ public void testDuplicateOperations() throws Exception { assertEquals(0L, wavelet.getCurrentVersion().getVersion()); // create the wavelet. WaveletDeltaRecord v0Response = wavelet.submitRequest( WAVELET_NAME, createProtocolSignedDelta(addParticipantOp, HASHED_VERSION_ZERO)); assertEquals(1L, wavelet.getCurrentVersion().getVersion()); ProtocolSignedDelta psd = createProtocolSignedDelta( addBlipOp, v0Response.getResultingVersion()); WaveletDeltaRecord dar1 = wavelet.submitRequest(WAVELET_NAME, psd); assertEquals(2L, wavelet.getCurrentVersion().getVersion()); WaveletDeltaRecord dar2 = wavelet.submitRequest(WAVELET_NAME, psd); assertEquals(2L, wavelet.getCurrentVersion().getVersion()); assertEquals(dar1.getResultingVersion(), dar2.getResultingVersion()); }
/** * Tests that duplicate operations are a no-op. * * @throws Exception should not be thrown. */ public void testDuplicateOperations() throws Exception { assertEquals(0L, wavelet.getCurrentVersion().getVersion()); // create the wavelet. WaveletDeltaRecord v0Response = wavelet.submitRequest( WAVELET_NAME, createProtocolSignedDelta(addParticipantOp, HASHED_VERSION_ZERO)); assertEquals(1L, wavelet.getCurrentVersion().getVersion()); ProtocolSignedDelta psd = createProtocolSignedDelta( addBlipOp, v0Response.getResultingVersion()); WaveletDeltaRecord dar1 = wavelet.submitRequest(WAVELET_NAME, psd); assertEquals(2L, wavelet.getCurrentVersion().getVersion()); WaveletDeltaRecord dar2 = wavelet.submitRequest(WAVELET_NAME, psd); assertEquals(2L, wavelet.getCurrentVersion().getVersion()); assertEquals(dar1.getResultingVersion(), dar2.getResultingVersion()); }
public void testSuccessfulLocalRequest() throws Exception { ProtocolSignedDelta addDelta = ProtocolSignedDelta.newBuilder() .addSignature(fakeSignature1) .setDelta(addParticipantProtoDelta(localWavelet).toByteString()) .build(); localWavelet.submitRequest(localWaveletName, addDelta); assertEquals(localWavelet.getCurrentVersion().getVersion(), 2); assertTrue(localWavelet.isDeltaSigner( localWavelet.getCurrentVersion(), fakeSigner1)); assertFalse(localWavelet.isDeltaSigner( localWavelet.getCurrentVersion(), fakeSigner2)); HashedVersion oldVersion = localWavelet.getCurrentVersion(); ProtocolSignedDelta removeDelta = ProtocolSignedDelta.newBuilder() .addSignature(fakeSignature2) .setDelta(ProtocolWaveletDelta.newBuilder(removeParticipantProtoDelta(localWavelet)) .setHashedVersion(serialize(localWavelet.getCurrentVersion())).build().toByteString()) .build(); localWavelet.submitRequest(localWaveletName, removeDelta); assertEquals(localWavelet.getCurrentVersion().getVersion(), 4); assertTrue(localWavelet.isDeltaSigner(oldVersion, fakeSigner1)); assertFalse(localWavelet.isDeltaSigner(oldVersion, fakeSigner2)); assertTrue(localWavelet.isDeltaSigner( localWavelet.getCurrentVersion(), fakeSigner2)); assertFalse(localWavelet.isDeltaSigner( localWavelet.getCurrentVersion(), fakeSigner1)); }
public void testSuccessfulLocalRequest() throws Exception { ProtocolSignedDelta addDelta = ProtocolSignedDelta.newBuilder() .addSignature(fakeSignature1) .setDelta(addParticipantProtoDelta(localWavelet).toByteString()) .build(); localWavelet.submitRequest(localWaveletName, addDelta); assertEquals(localWavelet.getCurrentVersion().getVersion(), 2); assertTrue(localWavelet.isDeltaSigner( localWavelet.getCurrentVersion(), fakeSigner1)); assertFalse(localWavelet.isDeltaSigner( localWavelet.getCurrentVersion(), fakeSigner2)); HashedVersion oldVersion = localWavelet.getCurrentVersion(); ProtocolSignedDelta removeDelta = ProtocolSignedDelta.newBuilder() .addSignature(fakeSignature2) .setDelta(ProtocolWaveletDelta.newBuilder(removeParticipantProtoDelta(localWavelet)) .setHashedVersion(serialize(localWavelet.getCurrentVersion())).build().toByteString()) .build(); localWavelet.submitRequest(localWaveletName, removeDelta); assertEquals(localWavelet.getCurrentVersion().getVersion(), 4); assertTrue(localWavelet.isDeltaSigner(oldVersion, fakeSigner1)); assertFalse(localWavelet.isDeltaSigner(oldVersion, fakeSigner2)); assertTrue(localWavelet.isDeltaSigner( localWavelet.getCurrentVersion(), fakeSigner2)); assertFalse(localWavelet.isDeltaSigner( localWavelet.getCurrentVersion(), fakeSigner1)); }
HashedVersion currentVersion = getCurrentVersion();
assertEquals(localWavelet.getCurrentVersion(), localVersion0); .addSignature(fakeSignature2) .setDelta(ProtocolWaveletDelta.newBuilder(addParticipantProtoDelta(localWavelet)) .setHashedVersion(serialize(localWavelet.getCurrentVersion())) .build().toByteString()) .build(); assertEquals(localWavelet.getCurrentVersion().getVersion(), 2); assertTrue(localWavelet.isDeltaSigner( localWavelet.getCurrentVersion(), fakeSigner1)); assertFalse(localWavelet.isDeltaSigner( localWavelet.getCurrentVersion(), fakeSigner2)); HashedVersion oldVersion = localWavelet.getCurrentVersion(); ProtocolSignedDelta rollbackDelta = ProtocolSignedDelta.newBuilder() .addSignature(fakeSignature1) .setDelta(ProtocolWaveletDelta.newBuilder(doubleRemoveParticipantProtoDelta(localWavelet)) .setHashedVersion(serialize(localWavelet.getCurrentVersion())) .build().toByteString()) .build(); assertEquals(localWavelet.getCurrentVersion(), oldVersion);
assertEquals(localWavelet.getCurrentVersion(), localVersion0); .addSignature(fakeSignature2) .setDelta(ProtocolWaveletDelta.newBuilder(addParticipantProtoDelta(localWavelet)) .setHashedVersion(serialize(localWavelet.getCurrentVersion())) .build().toByteString()) .build(); assertEquals(localWavelet.getCurrentVersion().getVersion(), 2); assertTrue(localWavelet.isDeltaSigner( localWavelet.getCurrentVersion(), fakeSigner1)); assertFalse(localWavelet.isDeltaSigner( localWavelet.getCurrentVersion(), fakeSigner2)); HashedVersion oldVersion = localWavelet.getCurrentVersion(); ProtocolSignedDelta rollbackDelta = ProtocolSignedDelta.newBuilder() .addSignature(fakeSignature1) .setDelta(ProtocolWaveletDelta.newBuilder(doubleRemoveParticipantProtoDelta(localWavelet)) .setHashedVersion(serialize(localWavelet.getCurrentVersion())) .build().toByteString()) .build(); assertEquals(localWavelet.getCurrentVersion(), oldVersion);
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 } }
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 } }