protected WaveletDeltaRecord createRecord() { HashedVersion targetVersion = HashedVersion.of(0, new byte[] {3, 2, 1}); HashedVersion resultingVersion = HashedVersion.of(2, new byte[] {1, 2, 3}); List<WaveletOperation> ops = ImmutableList.of(UTIL.noOp(), UTIL.addParticipant(TestingConstants.OTHER_PARTICIPANT)); TransformedWaveletDelta transformed = TransformedWaveletDelta.cloneOperations( TestingConstants.PARTICIPANT, resultingVersion, 1234567890, ops); ProtocolWaveletDelta serializedDelta = CoreWaveletOperationSerializer.serialize(transformed); ProtocolSignature signature = ProtocolSignature.newBuilder().setSignatureAlgorithm(SignatureAlgorithm.SHA1_RSA) .setSignatureBytes(ByteString.copyFrom(new byte[] {1, 2, 3})).setSignerId( ByteString.copyFromUtf8("somebody")).build(); ProtocolSignedDelta signedDelta = ProtocolSignedDelta.newBuilder().setDelta( ByteStringMessage.serializeMessage(serializedDelta).getByteString()).addAllSignature( ImmutableList.of(signature)).build(); ProtocolAppliedWaveletDelta delta = ProtocolAppliedWaveletDelta.newBuilder().setApplicationTimestamp(1234567890) .setHashedVersionAppliedAt(CoreWaveletOperationSerializer.serialize(targetVersion)) .setSignedOriginalDelta(signedDelta).setOperationsApplied(2).build(); return new WaveletDeltaRecord(targetVersion, ByteStringMessage.serializeMessage(delta), transformed); }
protected WaveletDeltaRecord createRecord() { HashedVersion targetVersion = HashedVersion.of(0, new byte[] {3, 2, 1}); HashedVersion resultingVersion = HashedVersion.of(2, new byte[] {1, 2, 3}); List<WaveletOperation> ops = ImmutableList.of(UTIL.noOp(), UTIL.addParticipant(TestingConstants.OTHER_PARTICIPANT)); TransformedWaveletDelta transformed = TransformedWaveletDelta.cloneOperations( TestingConstants.PARTICIPANT, resultingVersion, 1234567890, ops); ProtocolWaveletDelta serializedDelta = CoreWaveletOperationSerializer.serialize(transformed); ProtocolSignature signature = ProtocolSignature.newBuilder().setSignatureAlgorithm(SignatureAlgorithm.SHA1_RSA) .setSignatureBytes(ByteString.copyFrom(new byte[] {1, 2, 3})).setSignerId( ByteString.copyFromUtf8("somebody")).build(); ProtocolSignedDelta signedDelta = ProtocolSignedDelta.newBuilder().setDelta( ByteStringMessage.serializeMessage(serializedDelta).getByteString()).addAllSignature( ImmutableList.of(signature)).build(); ProtocolAppliedWaveletDelta delta = ProtocolAppliedWaveletDelta.newBuilder().setApplicationTimestamp(1234567890) .setHashedVersionAppliedAt(CoreWaveletOperationSerializer.serialize(targetVersion)) .setSignedOriginalDelta(signedDelta).setOperationsApplied(2).build(); return new WaveletDeltaRecord(targetVersion, ByteStringMessage.serializeMessage(delta), transformed); }
/** * Creates an applied delta message from a signed protocol delta and * application metadata. * * @param signedDelta the original delta * @param appliedAtVersion version at which the delta applied * @param operationsApplied number of ops in the delta * @param applicationTimestamp timestamp of application */ public static ByteStringMessage<ProtocolAppliedWaveletDelta> buildAppliedDelta( ProtocolSignedDelta signedDelta, HashedVersion appliedAtVersion, int operationsApplied, long applicationTimestamp) { ProtocolAppliedWaveletDelta.Builder appliedDeltaBuilder = ProtocolAppliedWaveletDelta .newBuilder() .setSignedOriginalDelta(signedDelta) .setOperationsApplied(operationsApplied) .setApplicationTimestamp(applicationTimestamp); // TODO(soren): Only set hashedVersionAppliedAt when different from the // signed delta's target version if we rev the protocol. appliedDeltaBuilder.setHashedVersionAppliedAt( CoreWaveletOperationSerializer.serialize(appliedAtVersion)); return ByteStringMessage.serializeMessage(appliedDeltaBuilder.build()); }