fixed serialization of RemoveKey

This commit is contained in:
gosubpl 2017-03-20 12:22:49 +01:00 committed by Patrik Nordwall
parent cc7065601a
commit dfbf50538e
4 changed files with 57 additions and 37 deletions

View file

@ -9846,17 +9846,17 @@ public final class ReplicatedDataMessages {
akka.protobuf.ByteString
getStringKeyBytes();
// required .akka.cluster.ddata.OtherMessage value = 2;
// optional .akka.cluster.ddata.OtherMessage value = 2;
/**
* <code>required .akka.cluster.ddata.OtherMessage value = 2;</code>
* <code>optional .akka.cluster.ddata.OtherMessage value = 2;</code>
*/
boolean hasValue();
/**
* <code>required .akka.cluster.ddata.OtherMessage value = 2;</code>
* <code>optional .akka.cluster.ddata.OtherMessage value = 2;</code>
*/
akka.cluster.ddata.protobuf.msg.ReplicatorMessages.OtherMessage getValue();
/**
* <code>required .akka.cluster.ddata.OtherMessage value = 2;</code>
* <code>optional .akka.cluster.ddata.OtherMessage value = 2;</code>
*/
akka.cluster.ddata.protobuf.msg.ReplicatorMessages.OtherMessageOrBuilder getValueOrBuilder();
@ -10069,23 +10069,23 @@ public final class ReplicatedDataMessages {
}
}
// required .akka.cluster.ddata.OtherMessage value = 2;
// optional .akka.cluster.ddata.OtherMessage value = 2;
public static final int VALUE_FIELD_NUMBER = 2;
private akka.cluster.ddata.protobuf.msg.ReplicatorMessages.OtherMessage value_;
/**
* <code>required .akka.cluster.ddata.OtherMessage value = 2;</code>
* <code>optional .akka.cluster.ddata.OtherMessage value = 2;</code>
*/
public boolean hasValue() {
return ((bitField0_ & 0x00000002) == 0x00000002);
}
/**
* <code>required .akka.cluster.ddata.OtherMessage value = 2;</code>
* <code>optional .akka.cluster.ddata.OtherMessage value = 2;</code>
*/
public akka.cluster.ddata.protobuf.msg.ReplicatorMessages.OtherMessage getValue() {
return value_;
}
/**
* <code>required .akka.cluster.ddata.OtherMessage value = 2;</code>
* <code>optional .akka.cluster.ddata.OtherMessage value = 2;</code>
*/
public akka.cluster.ddata.protobuf.msg.ReplicatorMessages.OtherMessageOrBuilder getValueOrBuilder() {
return value_;
@ -10157,14 +10157,12 @@ public final class ReplicatedDataMessages {
byte isInitialized = memoizedIsInitialized;
if (isInitialized != -1) return isInitialized == 1;
if (!hasValue()) {
memoizedIsInitialized = 0;
return false;
}
if (hasValue()) {
if (!getValue().isInitialized()) {
memoizedIsInitialized = 0;
return false;
}
}
if (hasOtherKey()) {
if (!getOtherKey().isInitialized()) {
memoizedIsInitialized = 0;
@ -10452,14 +10450,12 @@ public final class ReplicatedDataMessages {
}
public final boolean isInitialized() {
if (!hasValue()) {
return false;
}
if (hasValue()) {
if (!getValue().isInitialized()) {
return false;
}
}
if (hasOtherKey()) {
if (!getOtherKey().isInitialized()) {
@ -10562,18 +10558,18 @@ public final class ReplicatedDataMessages {
return this;
}
// required .akka.cluster.ddata.OtherMessage value = 2;
// optional .akka.cluster.ddata.OtherMessage value = 2;
private akka.cluster.ddata.protobuf.msg.ReplicatorMessages.OtherMessage value_ = akka.cluster.ddata.protobuf.msg.ReplicatorMessages.OtherMessage.getDefaultInstance();
private akka.protobuf.SingleFieldBuilder<
akka.cluster.ddata.protobuf.msg.ReplicatorMessages.OtherMessage, akka.cluster.ddata.protobuf.msg.ReplicatorMessages.OtherMessage.Builder, akka.cluster.ddata.protobuf.msg.ReplicatorMessages.OtherMessageOrBuilder> valueBuilder_;
/**
* <code>required .akka.cluster.ddata.OtherMessage value = 2;</code>
* <code>optional .akka.cluster.ddata.OtherMessage value = 2;</code>
*/
public boolean hasValue() {
return ((bitField0_ & 0x00000002) == 0x00000002);
}
/**
* <code>required .akka.cluster.ddata.OtherMessage value = 2;</code>
* <code>optional .akka.cluster.ddata.OtherMessage value = 2;</code>
*/
public akka.cluster.ddata.protobuf.msg.ReplicatorMessages.OtherMessage getValue() {
if (valueBuilder_ == null) {
@ -10583,7 +10579,7 @@ public final class ReplicatedDataMessages {
}
}
/**
* <code>required .akka.cluster.ddata.OtherMessage value = 2;</code>
* <code>optional .akka.cluster.ddata.OtherMessage value = 2;</code>
*/
public Builder setValue(akka.cluster.ddata.protobuf.msg.ReplicatorMessages.OtherMessage value) {
if (valueBuilder_ == null) {
@ -10599,7 +10595,7 @@ public final class ReplicatedDataMessages {
return this;
}
/**
* <code>required .akka.cluster.ddata.OtherMessage value = 2;</code>
* <code>optional .akka.cluster.ddata.OtherMessage value = 2;</code>
*/
public Builder setValue(
akka.cluster.ddata.protobuf.msg.ReplicatorMessages.OtherMessage.Builder builderForValue) {
@ -10613,7 +10609,7 @@ public final class ReplicatedDataMessages {
return this;
}
/**
* <code>required .akka.cluster.ddata.OtherMessage value = 2;</code>
* <code>optional .akka.cluster.ddata.OtherMessage value = 2;</code>
*/
public Builder mergeValue(akka.cluster.ddata.protobuf.msg.ReplicatorMessages.OtherMessage value) {
if (valueBuilder_ == null) {
@ -10632,7 +10628,7 @@ public final class ReplicatedDataMessages {
return this;
}
/**
* <code>required .akka.cluster.ddata.OtherMessage value = 2;</code>
* <code>optional .akka.cluster.ddata.OtherMessage value = 2;</code>
*/
public Builder clearValue() {
if (valueBuilder_ == null) {
@ -10645,7 +10641,7 @@ public final class ReplicatedDataMessages {
return this;
}
/**
* <code>required .akka.cluster.ddata.OtherMessage value = 2;</code>
* <code>optional .akka.cluster.ddata.OtherMessage value = 2;</code>
*/
public akka.cluster.ddata.protobuf.msg.ReplicatorMessages.OtherMessage.Builder getValueBuilder() {
bitField0_ |= 0x00000002;
@ -10653,7 +10649,7 @@ public final class ReplicatedDataMessages {
return getValueFieldBuilder().getBuilder();
}
/**
* <code>required .akka.cluster.ddata.OtherMessage value = 2;</code>
* <code>optional .akka.cluster.ddata.OtherMessage value = 2;</code>
*/
public akka.cluster.ddata.protobuf.msg.ReplicatorMessages.OtherMessageOrBuilder getValueOrBuilder() {
if (valueBuilder_ != null) {
@ -10663,7 +10659,7 @@ public final class ReplicatedDataMessages {
}
}
/**
* <code>required .akka.cluster.ddata.OtherMessage value = 2;</code>
* <code>optional .akka.cluster.ddata.OtherMessage value = 2;</code>
*/
private akka.protobuf.SingleFieldBuilder<
akka.cluster.ddata.protobuf.msg.ReplicatorMessages.OtherMessage, akka.cluster.ddata.protobuf.msg.ReplicatorMessages.OtherMessage.Builder, akka.cluster.ddata.protobuf.msg.ReplicatorMessages.OtherMessageOrBuilder>
@ -18396,7 +18392,7 @@ public final class ReplicatedDataMessages {
"age\"\263\003\n\017ORMapDeltaGroup\022:\n\007entries\030\001 \003(\013" +
"2).akka.cluster.ddata.ORMapDeltaGroup.En" +
"try\032\243\001\n\010MapEntry\022\021\n\tstringKey\030\001 \001(\t\022/\n\005v" +
"alue\030\002 \002(\0132 .akka.cluster.ddata.OtherMes" +
"alue\030\002 \001(\0132 .akka.cluster.ddata.OtherMes" +
"sage\022\016\n\006intKey\030\003 \001(\021\022\017\n\007longKey\030\004 \001(\022\0222\n" +
"\010otherKey\030\005 \001(\0132 .akka.cluster.ddata.Oth" +
"erMessage\032\275\001\n\005Entry\0223\n\toperation\030\001 \002(\0162 ",

View file

@ -78,7 +78,7 @@ message ORMap {
message ORMapDeltaGroup {
message MapEntry {
optional string stringKey = 1;
required OtherMessage value = 2;
optional OtherMessage value = 2;
optional sint32 intKey = 3;
optional sint64 longKey = 4;
optional OtherMessage otherKey = 5;

View file

@ -585,6 +585,13 @@ class ReplicatedDataSerializer(val system: ExtendedActorSystem)
}
}
def singleKeyEntryFromProto[PEntry <: GeneratedMessage, A <: GeneratedMessage](entry: PEntry)(implicit eh: ProtoMapEntryReader[PEntry, A]): Any =
if (eh.hasStringKey(entry)) eh.getStringKey(entry)
else if (eh.hasIntKey(entry)) eh.getIntKey(entry)
else if (eh.hasLongKey(entry)) eh.getLongKey(entry)
else if (eh.hasOtherKey(entry)) otherMessageFromProto(eh.getOtherKey(entry))
else throw new IllegalArgumentException(s"Can't deserialize the key in the ORMap delta")
// wire protocol is always DeltaGroup
private def ormapPutFromBinary(bytes: Array[Byte]): ORMap.PutDeltaOp[Any, ReplicatedData] = {
val group = ormapDeltaGroupFromBinary(bytes)
@ -641,8 +648,8 @@ class ReplicatedDataSerializer(val system: ExtendedActorSystem)
} else if (entry.getOperation == rd.ORMapDeltaOp.ORMapRemove) {
ORMap.RemoveDeltaOp(ORSet.RemoveDeltaOp(orsetFromProto(entry.getUnderlying)), zeroTagFromCode(entry.getZeroTag))
} else if (entry.getOperation == rd.ORMapDeltaOp.ORMapRemoveKey) {
val map = singleMapEntryFromProto(entry.getEntryData, (v: dm.OtherMessage) otherMessageFromProto(v).asInstanceOf[ReplicatedData])
ORMap.RemoveKeyDeltaOp(ORSet.RemoveDeltaOp(orsetFromProto(entry.getUnderlying)), map.keySet.head, zeroTagFromCode(entry.getZeroTag))
val elem = singleKeyEntryFromProto(entry.getEntryData)
ORMap.RemoveKeyDeltaOp(ORSet.RemoveDeltaOp(orsetFromProto(entry.getUnderlying)), elem, zeroTagFromCode(entry.getZeroTag))
} else if (entry.getOperation == rd.ORMapDeltaOp.ORMapUpdate) {
val map = singleMapEntryFromProto(entry.getEntryData, (v: dm.OtherMessage) otherMessageFromProto(v).asInstanceOf[ReplicatedDelta])
ORMap.UpdateDeltaOp(ORSet.AddDeltaOp(orsetFromProto(entry.getUnderlying)), map, zeroTagFromCode(entry.getZeroTag))
@ -690,6 +697,22 @@ class ReplicatedDataSerializer(val system: ExtendedActorSystem)
}
}
def createEntryWithKey(opType: rd.ORMapDeltaOp, u: ORSet[_], k: Any, zt: Int) = {
val entryDataBuilder = rd.ORMapDeltaGroup.MapEntry.newBuilder()
k match {
case key: String entryDataBuilder.setStringKey(key)
case key: Int entryDataBuilder.setIntKey(key)
case key: Long entryDataBuilder.setLongKey(key)
case key entryDataBuilder.setOtherKey(otherMessageToProto(key))
}
val builder = rd.ORMapDeltaGroup.Entry.newBuilder()
.setOperation(opType)
.setUnderlying(orsetToProto(u))
.setZeroTag(zt)
builder.setEntryData(entryDataBuilder.build())
builder
}
val b = rd.ORMapDeltaGroup.newBuilder()
deltaGroup.ops.foreach {
case ORMap.PutDeltaOp(op, pair, zt)
@ -697,7 +720,7 @@ class ReplicatedDataSerializer(val system: ExtendedActorSystem)
case ORMap.RemoveDeltaOp(op, zt)
b.addEntries(createEntry(rd.ORMapDeltaOp.ORMapRemove, op.asInstanceOf[ORSet.RemoveDeltaOp[_]].underlying, Map.empty, zt.value))
case ORMap.RemoveKeyDeltaOp(op, k, zt)
b.addEntries(createEntry(rd.ORMapDeltaOp.ORMapRemoveKey, op.asInstanceOf[ORSet.RemoveDeltaOp[_]].underlying, Map(k k), zt.value))
b.addEntries(createEntryWithKey(rd.ORMapDeltaOp.ORMapRemoveKey, op.asInstanceOf[ORSet.RemoveDeltaOp[_]].underlying, k, zt.value))
case ORMap.UpdateDeltaOp(op, m, zt)
b.addEntries(createEntry(rd.ORMapDeltaOp.ORMapUpdate, op.asInstanceOf[ORSet.AddDeltaOp[_]].underlying, m, zt.value))
case ORMap.DeltaGroup(u)

View file

@ -277,6 +277,7 @@ class ReplicatedDataSerializerSpec extends TestKit(ActorSystem(
checkSerialization(ORMultiMap._emptyWithValueDeltas.addBinding(address1, 1, "A"))
checkSerialization(ORMultiMap._emptyWithValueDeltas.addBinding(address1, 1L, "A"))
checkSerialization(ORMultiMap._emptyWithValueDeltas.addBinding(address1, Flag(), "A"))
checkSerialization(ORMultiMap.emptyWithValueDeltas[String, String].addBinding(address1, "a", "A").remove(address1, "a").delta.get)
checkSerialization(ORMultiMap.emptyWithValueDeltas[String, String]
.addBinding(address1, "a", "A1")
.put(address2, "b", Set("B1", "B2", "B3"))