private void submitDeltaToNewWavelet(WaveletName name, ParticipantId user, WaveletOperation... ops) throws Exception { HashedVersion version = V0_HASH_FACTORY.createVersionZero(name); WaveletDelta delta = new WaveletDelta(user, version, Arrays.asList(ops)); addWaveletToUserView(name, user); ProtocolWaveletDelta protoDelta = CoreWaveletOperationSerializer.serialize(delta); // Submitting the request will require the certificate manager to sign the delta. We'll just // leave it unsigned. ProtocolSignedDelta signedProtoDelta = ProtocolSignedDelta.newBuilder().setDelta(protoDelta.toByteString()).build(); LocalWaveletContainer wavelet = waveMap.getOrCreateLocalWavelet(name); wavelet.submitRequest(name, signedProtoDelta); }
private void submitDeltaToNewWavelet(WaveletName name, ParticipantId user, WaveletOperation... ops) { HashedVersion version = V0_HASH_FACTORY.createVersionZero(name); WaveletDelta delta = new WaveletDelta(user, version, ImmutableList.copyOf(ops)); ProtocolWaveletDelta protoDelta = CoreWaveletOperationSerializer.serialize(delta); // Submitting the request will require the certificate manager to sign the delta. We'll just // leave it unsigned. ProtocolSignedDelta signedProtoDelta = ProtocolSignedDelta.newBuilder().setDelta(protoDelta.toByteString()).build(); waveServer.submitRequest(name, protoDelta, new SubmitRequestListener() { @Override public void onSuccess(int operationsApplied, HashedVersion hashedVersionAfterApplication, long applicationTimestamp) { // Wavelet was submitted. } @Override public void onFailure(String errorMessage) { fail("Could not submit callback"); } }); } }
private void submitDeltaToNewWavelet(WaveletName name, ParticipantId user, WaveletOperation... ops) throws Exception { HashedVersion version = V0_HASH_FACTORY.createVersionZero(name); WaveletDelta delta = new WaveletDelta(user, version, Arrays.asList(ops)); addWaveletToUserView(name, user); ProtocolWaveletDelta protoDelta = CoreWaveletOperationSerializer.serialize(delta); // Submitting the request will require the certificate manager to sign the delta. We'll just // leave it unsigned. ProtocolSignedDelta signedProtoDelta = ProtocolSignedDelta.newBuilder().setDelta(protoDelta.toByteString()).build(); LocalWaveletContainer wavelet = waveMap.getOrCreateLocalWavelet(name); wavelet.submitRequest(name, signedProtoDelta); }
public void testFailedLocalWaveletRequest() throws Exception { ProtocolSignedDelta removeDelta = ProtocolSignedDelta.newBuilder() .addSignature(fakeSignature1) .setDelta(removeParticipantProtoDelta(localWavelet).toByteString()) .build(); try { .setDelta(addParticipantProtoDelta(localWavelet).toByteString()) .build(); .setDelta(ProtocolWaveletDelta.newBuilder(addParticipantProtoDelta(localWavelet)) .setHashedVersion(serialize(localWavelet.getCurrentVersion())) .build().toByteString()) .build(); localWavelet.submitRequest(localWaveletName, addAgainDelta); .setDelta(ProtocolWaveletDelta.newBuilder(doubleRemoveParticipantProtoDelta(localWavelet)) .setHashedVersion(serialize(localWavelet.getCurrentVersion())) .build().toByteString()) .build(); try {
public void testFailedLocalWaveletRequest() throws Exception { ProtocolSignedDelta removeDelta = ProtocolSignedDelta.newBuilder() .addSignature(fakeSignature1) .setDelta(removeParticipantProtoDelta(localWavelet).toByteString()) .build(); try { .setDelta(addParticipantProtoDelta(localWavelet).toByteString()) .build(); .setDelta(ProtocolWaveletDelta.newBuilder(addParticipantProtoDelta(localWavelet)) .setHashedVersion(serialize(localWavelet.getCurrentVersion())) .build().toByteString()) .build(); localWavelet.submitRequest(localWaveletName, addAgainDelta); .setDelta(ProtocolWaveletDelta.newBuilder(doubleRemoveParticipantProtoDelta(localWavelet)) .setHashedVersion(serialize(localWavelet.getCurrentVersion())) .build().toByteString()) .build(); try {
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)); }
private void submitDeltaToNewWavelet(WaveletName name, ParticipantId user, WaveletOperation... ops) { HashedVersion version = V0_HASH_FACTORY.createVersionZero(name); WaveletDelta delta = new WaveletDelta(user, version, ImmutableList.copyOf(ops)); ProtocolWaveletDelta protoDelta = CoreWaveletOperationSerializer.serialize(delta); // Submitting the request will require the certificate manager to sign the delta. We'll just // leave it unsigned. ProtocolSignedDelta signedProtoDelta = ProtocolSignedDelta.newBuilder().setDelta(protoDelta.toByteString()).build(); waveServer.submitRequest(name, protoDelta, new SubmitRequestListener() { @Override public void onSuccess(int operationsApplied, HashedVersion hashedVersionAfterApplication, long applicationTimestamp) { // Wavelet was submitted. } @Override public void onFailure(String errorMessage) { fail("Could not submit callback"); } }); } }
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 testLocalEmptyDelta() throws Exception { ProtocolSignedDelta emptyDelta = ProtocolSignedDelta.newBuilder() .addSignature(fakeSignature1) .setDelta(ProtocolWaveletDelta.newBuilder() .setAuthor(author.toString()) .setHashedVersion(serialize(localVersion0)) .build().toByteString()) .build(); try { localWavelet.submitRequest(localWaveletName, emptyDelta); fail("Should fail"); } catch (IllegalArgumentException e) { // Correct } }
public void testLocalEmptyDelta() throws Exception { ProtocolSignedDelta emptyDelta = ProtocolSignedDelta.newBuilder() .addSignature(fakeSignature1) .setDelta(ProtocolWaveletDelta.newBuilder() .setAuthor(author.toString()) .setHashedVersion(serialize(localVersion0)) .build().toByteString()) .build(); try { localWavelet.submitRequest(localWaveletName, emptyDelta); fail("Should fail"); } catch (IllegalArgumentException e) { // Correct } }
private ProtocolSignedDelta createProtocolSignedDelta(ProtocolWaveletOperation operation, HashedVersion protocolHashedVersion) { ProtocolWaveletDelta delta = ProtocolWaveletDelta.newBuilder() .setAuthor(AUTHOR) .setHashedVersion(CoreWaveletOperationSerializer.serialize(protocolHashedVersion)) .addOperation(operation) .build(); return ProtocolSignedDelta.newBuilder() .setDelta(delta.toByteString()) .addSignature(SIGNATURE) .build(); } }
private ProtocolSignedDelta createProtocolSignedDelta(ProtocolWaveletOperation operation, HashedVersion protocolHashedVersion) { ProtocolWaveletDelta delta = ProtocolWaveletDelta.newBuilder() .setAuthor(AUTHOR) .setHashedVersion(CoreWaveletOperationSerializer.serialize(protocolHashedVersion)) .addOperation(operation) .build(); return ProtocolSignedDelta.newBuilder() .setDelta(delta.toByteString()) .addSignature(SIGNATURE) .build(); } }