/** * Builds a {@link WaveletDeltaRecord} and applies it to the wavelet container. * The delta must be non-empty. */ protected WaveletDeltaRecord applyDelta( ByteStringMessage<ProtocolAppliedWaveletDelta> appliedDelta, WaveletDelta transformed) throws InvalidProtocolBufferException, OperationException { TransformedWaveletDelta transformedDelta = AppliedDeltaUtil.buildTransformedDelta(appliedDelta, transformed); WaveletDeltaRecord deltaRecord = new WaveletDeltaRecord(transformed.getTargetVersion(), appliedDelta, transformedDelta); waveletState.appendDelta(deltaRecord); return deltaRecord; }
/** * Read a record and return it. */ private WaveletDeltaRecord readRecord() throws IOException { DeltaHeader header = readDeltaHeader(); ByteStringMessage<ProtocolAppliedWaveletDelta> appliedDelta = readAppliedDelta(header.appliedDeltaLength); TransformedWaveletDelta transformedDelta = readTransformedWaveletDelta( header.transformedDeltaLength); return new WaveletDeltaRecord(AppliedDeltaUtil.getHashedVersionAppliedAt(appliedDelta), appliedDelta, transformedDelta); }
public static WaveletDeltaRecord deserializeWaveletDeltaRecord(DBObject dbObject) throws PersistenceException { try { return new WaveletDeltaRecord( deserializeHashedVersion((DBObject) dbObject.get(FIELD_APPLIEDATVERSION)), ByteStringMessage.parseProtocolAppliedWaveletDelta(ByteString.copyFrom((byte[]) dbObject .get(FIELD_APPLIED))), deserializeTransformedWaveletDelta((DBObject) dbObject.get(FIELD_TRANSFORMED))); } catch (InvalidProtocolBufferException e) { throw new PersistenceException(e); } }
/** * 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); } }
/** * 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); } }
return new WaveletDeltaRecord(transformed.getTargetVersion(), null, emptyDelta); transformed, dupDelta); return new WaveletDeltaRecord(transformed.getTargetVersion(), existingDeltaBytes, dupDelta);
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); }