From ae11ac10dfd3579b1b685455ea642bbb08de68f1 Mon Sep 17 00:00:00 2001 From: Tom Pantelis Date: Sat, 23 Jan 2016 00:31:21 -0500 Subject: [PATCH] Deprecate CloseTransactionChain protobuff message Deprecate the associated CloseTransactionChain protobuff message and change the message classes to extend VersionedExternalizableMessage. Backwards compatibility with pre-boron is maintained. Related code was modified accordingly. The CloseTransactionChainReply message isn't used so it was removed. Change-Id: I58d29eac9cb2f300f92dd4e5cb11484b215ddc48 Signed-off-by: Tom Pantelis --- .../ShardTransactionChainMessages.java | 118 +++++++++++++----- .../controller/cluster/datastore/Shard.java | 2 +- .../datastore/TransactionChainProxy.java | 9 +- .../messages/CloseTransactionChain.java | 61 ++++++--- .../messages/CloseTransactionChainReply.java | 26 ---- .../cluster/datastore/utils/ActorContext.java | 4 +- .../datastore/TransactionChainProxyTest.java | 5 +- .../messages/CloseTransactionChainTest.java | 58 +++++++++ .../datastore/utils/ActorContextTest.java | 8 +- 9 files changed, 213 insertions(+), 78 deletions(-) delete mode 100644 opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/CloseTransactionChainReply.java create mode 100644 opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/messages/CloseTransactionChainTest.java diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/protobuff/messages/transaction/ShardTransactionChainMessages.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/protobuff/messages/transaction/ShardTransactionChainMessages.java index feb60ae829..c3f7d98b55 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/protobuff/messages/transaction/ShardTransactionChainMessages.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/protobuff/messages/transaction/ShardTransactionChainMessages.java @@ -3,6 +3,7 @@ package org.opendaylight.controller.protobuff.messages.transaction; +@Deprecated public final class ShardTransactionChainMessages { private ShardTransactionChainMessages() {} public static void registerAllExtensions( @@ -44,6 +45,7 @@ public final class ShardTransactionChainMessages { return defaultInstance; } + @Override public CloseTransactionChain getDefaultInstanceForType() { return defaultInstance; } @@ -99,6 +101,7 @@ public final class ShardTransactionChainMessages { return org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.internal_static_org_opendaylight_controller_mdsal_CloseTransactionChain_descriptor; } + @Override protected com.google.protobuf.GeneratedMessage.FieldAccessorTable internalGetFieldAccessorTable() { return org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.internal_static_org_opendaylight_controller_mdsal_CloseTransactionChain_fieldAccessorTable @@ -108,7 +111,8 @@ public final class ShardTransactionChainMessages { public static com.google.protobuf.Parser PARSER = new com.google.protobuf.AbstractParser() { - public CloseTransactionChain parsePartialFrom( + @Override + public CloseTransactionChain parsePartialFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { @@ -128,12 +132,14 @@ public final class ShardTransactionChainMessages { /** * optional string transactionChainId = 1; */ + @Override public boolean hasTransactionChainId() { return ((bitField0_ & 0x00000001) == 0x00000001); } /** * optional string transactionChainId = 1; */ + @Override public java.lang.String getTransactionChainId() { java.lang.Object ref = transactionChainId_; if (ref instanceof java.lang.String) { @@ -151,6 +157,7 @@ public final class ShardTransactionChainMessages { /** * optional string transactionChainId = 1; */ + @Override public com.google.protobuf.ByteString getTransactionChainIdBytes() { java.lang.Object ref = transactionChainId_; @@ -169,14 +176,18 @@ public final class ShardTransactionChainMessages { transactionChainId_ = ""; } private byte memoizedIsInitialized = -1; + @Override public final boolean isInitialized() { byte isInitialized = memoizedIsInitialized; - if (isInitialized != -1) return isInitialized == 1; + if (isInitialized != -1) { + return isInitialized == 1; + } memoizedIsInitialized = 1; return true; } + @Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { getSerializedSize(); @@ -187,9 +198,12 @@ public final class ShardTransactionChainMessages { } private int memoizedSerializedSize = -1; + @Override public int getSerializedSize() { int size = memoizedSerializedSize; - if (size != -1) return size; + if (size != -1) { + return size; + } size = 0; if (((bitField0_ & 0x00000001) == 0x00000001)) { @@ -262,10 +276,12 @@ public final class ShardTransactionChainMessages { } public static Builder newBuilder() { return Builder.create(); } + @Override public Builder newBuilderForType() { return newBuilder(); } public static Builder newBuilder(org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChain prototype) { return newBuilder().mergeFrom(prototype); } + @Override public Builder toBuilder() { return newBuilder(this); } @java.lang.Override @@ -285,7 +301,8 @@ public final class ShardTransactionChainMessages { return org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.internal_static_org_opendaylight_controller_mdsal_CloseTransactionChain_descriptor; } - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + @Override + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable internalGetFieldAccessorTable() { return org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.internal_static_org_opendaylight_controller_mdsal_CloseTransactionChain_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -310,27 +327,32 @@ public final class ShardTransactionChainMessages { return new Builder(); } - public Builder clear() { + @Override + public Builder clear() { super.clear(); transactionChainId_ = ""; bitField0_ = (bitField0_ & ~0x00000001); return this; } - public Builder clone() { + @Override + public Builder clone() { return create().mergeFrom(buildPartial()); } - public com.google.protobuf.Descriptors.Descriptor + @Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { return org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.internal_static_org_opendaylight_controller_mdsal_CloseTransactionChain_descriptor; } - public org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChain getDefaultInstanceForType() { + @Override + public org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChain getDefaultInstanceForType() { return org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChain.getDefaultInstance(); } - public org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChain build() { + @Override + public org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChain build() { org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChain result = buildPartial(); if (!result.isInitialized()) { throw newUninitializedMessageException(result); @@ -338,7 +360,8 @@ public final class ShardTransactionChainMessages { return result; } - public org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChain buildPartial() { + @Override + public org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChain buildPartial() { org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChain result = new org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChain(this); int from_bitField0_ = bitField0_; int to_bitField0_ = 0; @@ -351,7 +374,8 @@ public final class ShardTransactionChainMessages { return result; } - public Builder mergeFrom(com.google.protobuf.Message other) { + @Override + public Builder mergeFrom(com.google.protobuf.Message other) { if (other instanceof org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChain) { return mergeFrom((org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChain)other); } else { @@ -361,7 +385,9 @@ public final class ShardTransactionChainMessages { } public Builder mergeFrom(org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChain other) { - if (other == org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChain.getDefaultInstance()) return this; + if (other == org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChain.getDefaultInstance()) { + return this; + } if (other.hasTransactionChainId()) { bitField0_ |= 0x00000001; transactionChainId_ = other.transactionChainId_; @@ -371,11 +397,13 @@ public final class ShardTransactionChainMessages { return this; } - public final boolean isInitialized() { + @Override + public final boolean isInitialized() { return true; } - public Builder mergeFrom( + @Override + public Builder mergeFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { @@ -399,13 +427,15 @@ public final class ShardTransactionChainMessages { /** * optional string transactionChainId = 1; */ - public boolean hasTransactionChainId() { + @Override + public boolean hasTransactionChainId() { return ((bitField0_ & 0x00000001) == 0x00000001); } /** * optional string transactionChainId = 1; */ - public java.lang.String getTransactionChainId() { + @Override + public java.lang.String getTransactionChainId() { java.lang.Object ref = transactionChainId_; if (!(ref instanceof java.lang.String)) { java.lang.String s = ((com.google.protobuf.ByteString) ref) @@ -419,7 +449,8 @@ public final class ShardTransactionChainMessages { /** * optional string transactionChainId = 1; */ - public com.google.protobuf.ByteString + @Override + public com.google.protobuf.ByteString getTransactionChainIdBytes() { java.lang.Object ref = transactionChainId_; if (ref instanceof String) { @@ -500,6 +531,7 @@ public final class ShardTransactionChainMessages { return defaultInstance; } + @Override public CloseTransactionChainReply getDefaultInstanceForType() { return defaultInstance; } @@ -549,6 +581,7 @@ public final class ShardTransactionChainMessages { return org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.internal_static_org_opendaylight_controller_mdsal_CloseTransactionChainReply_descriptor; } + @Override protected com.google.protobuf.GeneratedMessage.FieldAccessorTable internalGetFieldAccessorTable() { return org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.internal_static_org_opendaylight_controller_mdsal_CloseTransactionChainReply_fieldAccessorTable @@ -558,7 +591,8 @@ public final class ShardTransactionChainMessages { public static com.google.protobuf.Parser PARSER = new com.google.protobuf.AbstractParser() { - public CloseTransactionChainReply parsePartialFrom( + @Override + public CloseTransactionChainReply parsePartialFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { @@ -574,14 +608,18 @@ public final class ShardTransactionChainMessages { private void initFields() { } private byte memoizedIsInitialized = -1; + @Override public final boolean isInitialized() { byte isInitialized = memoizedIsInitialized; - if (isInitialized != -1) return isInitialized == 1; + if (isInitialized != -1) { + return isInitialized == 1; + } memoizedIsInitialized = 1; return true; } + @Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { getSerializedSize(); @@ -589,9 +627,12 @@ public final class ShardTransactionChainMessages { } private int memoizedSerializedSize = -1; + @Override public int getSerializedSize() { int size = memoizedSerializedSize; - if (size != -1) return size; + if (size != -1) { + return size; + } size = 0; size += getUnknownFields().getSerializedSize(); @@ -660,10 +701,12 @@ public final class ShardTransactionChainMessages { } public static Builder newBuilder() { return Builder.create(); } + @Override public Builder newBuilderForType() { return newBuilder(); } public static Builder newBuilder(org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChainReply prototype) { return newBuilder().mergeFrom(prototype); } + @Override public Builder toBuilder() { return newBuilder(this); } @java.lang.Override @@ -683,7 +726,8 @@ public final class ShardTransactionChainMessages { return org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.internal_static_org_opendaylight_controller_mdsal_CloseTransactionChainReply_descriptor; } - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + @Override + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable internalGetFieldAccessorTable() { return org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.internal_static_org_opendaylight_controller_mdsal_CloseTransactionChainReply_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -708,25 +752,30 @@ public final class ShardTransactionChainMessages { return new Builder(); } - public Builder clear() { + @Override + public Builder clear() { super.clear(); return this; } - public Builder clone() { + @Override + public Builder clone() { return create().mergeFrom(buildPartial()); } - public com.google.protobuf.Descriptors.Descriptor + @Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { return org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.internal_static_org_opendaylight_controller_mdsal_CloseTransactionChainReply_descriptor; } - public org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChainReply getDefaultInstanceForType() { + @Override + public org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChainReply getDefaultInstanceForType() { return org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChainReply.getDefaultInstance(); } - public org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChainReply build() { + @Override + public org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChainReply build() { org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChainReply result = buildPartial(); if (!result.isInitialized()) { throw newUninitializedMessageException(result); @@ -734,13 +783,15 @@ public final class ShardTransactionChainMessages { return result; } - public org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChainReply buildPartial() { + @Override + public org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChainReply buildPartial() { org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChainReply result = new org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChainReply(this); onBuilt(); return result; } - public Builder mergeFrom(com.google.protobuf.Message other) { + @Override + public Builder mergeFrom(com.google.protobuf.Message other) { if (other instanceof org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChainReply) { return mergeFrom((org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChainReply)other); } else { @@ -750,16 +801,20 @@ public final class ShardTransactionChainMessages { } public Builder mergeFrom(org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChainReply other) { - if (other == org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChainReply.getDefaultInstance()) return this; + if (other == org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages.CloseTransactionChainReply.getDefaultInstance()) { + return this; + } this.mergeUnknownFields(other.getUnknownFields()); return this; } - public final boolean isInitialized() { + @Override + public final boolean isInitialized() { return true; } - public Builder mergeFrom( + @Override + public Builder mergeFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { @@ -816,6 +871,7 @@ public final class ShardTransactionChainMessages { }; com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() { + @Override public com.google.protobuf.ExtensionRegistry assignDescriptors( com.google.protobuf.Descriptors.FileDescriptor root) { descriptor = root; diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java index 74e25323bc..b63cb862ac 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java @@ -240,7 +240,7 @@ public class Shard extends RaftActor { handleCommitTransaction(CommitTransaction.fromSerializable(message)); } else if (AbortTransaction.isSerializedType(message)) { handleAbortTransaction(AbortTransaction.fromSerializable(message)); - } else if (CloseTransactionChain.SERIALIZABLE_CLASS.isInstance(message)) { + } else if (CloseTransactionChain.isSerializedType(message)) { closeTransactionChain(CloseTransactionChain.fromSerializable(message)); } else if (message instanceof RegisterChangeListener) { changeSupport.onMessage((RegisterChangeListener) message, isLeader(), hasLeader()); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxy.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxy.java index d230a956c2..cf00d5fa39 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxy.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxy.java @@ -19,6 +19,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; +import java.util.function.Function; import javax.annotation.Nonnull; import org.opendaylight.controller.cluster.datastore.identifiers.TransactionChainIdentifier; import org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier; @@ -184,7 +185,13 @@ final class TransactionChainProxy extends AbstractTransactionContextFactory() { + @Override + public Object apply(Short version) { + return new CloseTransactionChain(transactionChainId.toString(), version).toSerializable(); + } + }); } private TransactionProxy allocateWriteTransaction(final TransactionType type) { diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/CloseTransactionChain.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/CloseTransactionChain.java index 7db39b77a3..bc59c544ca 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/CloseTransactionChain.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/CloseTransactionChain.java @@ -8,31 +8,64 @@ package org.opendaylight.controller.cluster.datastore.messages; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import org.opendaylight.controller.cluster.datastore.DataStoreVersions; import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages; -public class CloseTransactionChain implements SerializableMessage { - public static final Class SERIALIZABLE_CLASS = - ShardTransactionChainMessages.CloseTransactionChain.class; - private final String transactionChainId; +public class CloseTransactionChain extends VersionedExternalizableMessage { + private static final long serialVersionUID = 1L; - public CloseTransactionChain(final String transactionChainId){ + private String transactionChainId; + + public CloseTransactionChain() { + } + + public CloseTransactionChain(final String transactionChainId, final short version) { + super(version); this.transactionChainId = transactionChainId; } + public String getTransactionChainId() { + return transactionChainId; + } + @Override - public Object toSerializable() { - return ShardTransactionChainMessages.CloseTransactionChain.newBuilder() - .setTransactionChainId(transactionChainId).build(); + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + super.readExternal(in); + transactionChainId = in.readUTF(); } - public static CloseTransactionChain fromSerializable(final Object message){ - ShardTransactionChainMessages.CloseTransactionChain closeTransactionChain - = (ShardTransactionChainMessages.CloseTransactionChain) message; + @Override + public void writeExternal(ObjectOutput out) throws IOException { + super.writeExternal(out); + out.writeUTF(transactionChainId); + } + + @Override + public Object toSerializable() { + if(getVersion() >= DataStoreVersions.BORON_VERSION) { + return this; + } else { + return ShardTransactionChainMessages.CloseTransactionChain.newBuilder() + .setTransactionChainId(transactionChainId).build(); + } + } - return new CloseTransactionChain(closeTransactionChain.getTransactionChainId()); + public static CloseTransactionChain fromSerializable(final Object serializable){ + if(serializable instanceof CloseTransactionChain) { + return (CloseTransactionChain)serializable; + } else { + ShardTransactionChainMessages.CloseTransactionChain closeTransactionChain = + (ShardTransactionChainMessages.CloseTransactionChain) serializable; + return new CloseTransactionChain(closeTransactionChain.getTransactionChainId(), + DataStoreVersions.LITHIUM_VERSION); + } } - public String getTransactionChainId() { - return transactionChainId; + public static boolean isSerializedType(Object message) { + return message instanceof CloseTransactionChain || + message instanceof ShardTransactionChainMessages.CloseTransactionChain; } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/CloseTransactionChainReply.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/CloseTransactionChainReply.java deleted file mode 100644 index b4673e8a08..0000000000 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/CloseTransactionChainReply.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.controller.cluster.datastore.messages; - -import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages; - -public class CloseTransactionChainReply implements SerializableMessage { - public static final Class SERIALIZABLE_CLASS = - ShardTransactionChainMessages.CloseTransactionChainReply.class; - - private static final Object SERIALIZED_INSTANCE = - ShardTransactionChainMessages.CloseTransactionChainReply.newBuilder().build(); - - public static final CloseTransactionChainReply INSTANCE = new CloseTransactionChainReply(); - - @Override - public Object toSerializable() { - return SERIALIZED_INSTANCE; - } -} diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/ActorContext.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/ActorContext.java index 1915621efd..e7ab144a5a 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/ActorContext.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/ActorContext.java @@ -25,6 +25,7 @@ import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.base.Strings; import java.util.concurrent.TimeUnit; +import java.util.function.Function; import org.opendaylight.controller.cluster.datastore.ClusterWrapper; import org.opendaylight.controller.cluster.datastore.DataStoreVersions; import org.opendaylight.controller.cluster.datastore.DatastoreContext; @@ -399,13 +400,14 @@ public class ActorContext { * * @param message */ - public void broadcast(final Object message){ + public void broadcast(final Function messageSupplier){ for(final String shardName : configuration.getAllShardNames()){ Future primaryFuture = findPrimaryShardAsync(shardName); primaryFuture.onComplete(new OnComplete() { @Override public void onComplete(Throwable failure, PrimaryShardInfo primaryShardInfo) { + Object message = messageSupplier.apply(primaryShardInfo.getPrimaryShardVersion()); if(failure != null) { LOG.warn("broadcast failed to send message {} to shard {}: {}", message.getClass().getSimpleName(), shardName, failure); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxyTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxyTest.java index 8338e7083a..66b8c0ec8d 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxyTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxyTest.java @@ -11,7 +11,6 @@ package org.opendaylight.controller.cluster.datastore; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyObject; import static org.mockito.Matchers.eq; import static org.mockito.Matchers.isA; import static org.mockito.Mockito.doReturn; @@ -21,12 +20,12 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.opendaylight.controller.cluster.datastore.TransactionType.READ_WRITE; import static org.opendaylight.controller.cluster.datastore.TransactionType.WRITE_ONLY; - import akka.actor.ActorRef; import akka.util.Timeout; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Function; import org.junit.Assert; import org.junit.Test; import org.opendaylight.controller.cluster.datastore.messages.BatchedModifications; @@ -72,7 +71,7 @@ public class TransactionChainProxyTest extends AbstractTransactionProxyTest { public void testClose() throws Exception { new TransactionChainProxy(mockComponentFactory).close(); - verify(mockActorContext, times(1)).broadcast(anyObject()); + verify(mockActorContext, times(1)).broadcast(any(Function.class)); } @Test diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/messages/CloseTransactionChainTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/messages/CloseTransactionChainTest.java new file mode 100644 index 0000000000..0e9c5d85d0 --- /dev/null +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/messages/CloseTransactionChainTest.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2016 Brocade Communications Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.cluster.datastore.messages; + +import static org.junit.Assert.assertEquals; +import java.io.Serializable; +import org.apache.commons.lang.SerializationUtils; +import org.junit.Test; +import org.opendaylight.controller.cluster.datastore.DataStoreVersions; +import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionChainMessages; + +/** + * Unit tests for CloseTransactionChain. + * + * @author Thomas Pantelis + */ +public class CloseTransactionChainTest { + + @Test + public void testSerialization() { + CloseTransactionChain expected = new CloseTransactionChain("txId", DataStoreVersions.CURRENT_VERSION); + + Object serialized = expected.toSerializable(); + assertEquals("Serialized type", CloseTransactionChain.class, serialized.getClass()); + + CloseTransactionChain actual = CloseTransactionChain.fromSerializable( + SerializationUtils.clone((Serializable) serialized)); + assertEquals("getTransactionChainId", expected.getTransactionChainId(), actual.getTransactionChainId()); + assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, actual.getVersion()); + } + + @Test + public void testSerializationWithPreBoronVersion() { + CloseTransactionChain expected = new CloseTransactionChain("txId", DataStoreVersions.LITHIUM_VERSION); + + Object serialized = expected.toSerializable(); + assertEquals("Serialized type", ShardTransactionChainMessages.CloseTransactionChain.class, serialized.getClass()); + + CloseTransactionChain actual = CloseTransactionChain.fromSerializable( + SerializationUtils.clone((Serializable) serialized)); + assertEquals("getTransactionChainId", expected.getTransactionChainId(), actual.getTransactionChainId()); + assertEquals("getVersion", DataStoreVersions.LITHIUM_VERSION, actual.getVersion()); + } + + @Test + public void testIsSerializedType() { + assertEquals("isSerializedType", true, CloseTransactionChain.isSerializedType( + ShardTransactionChainMessages.CloseTransactionChain.newBuilder().setTransactionChainId("").build())); + + assertEquals("isSerializedType", true, CloseTransactionChain.isSerializedType(new CloseTransactionChain())); + assertEquals("isSerializedType", false, CloseTransactionChain.isSerializedType(new Object())); + } +} diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/ActorContextTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/ActorContextTest.java index 14536ba7a0..405fe5221b 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/ActorContextTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/ActorContextTest.java @@ -35,6 +35,7 @@ import com.typesafe.config.ConfigFactory; import java.util.Arrays; import java.util.Map; import java.util.concurrent.TimeUnit; +import java.util.function.Function; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; @@ -497,7 +498,12 @@ public class ActorContextTest extends AbstractActorTest{ mock(ClusterWrapper.class), mockConfig, DatastoreContext.newBuilder().shardInitializationTimeout(200, TimeUnit.MILLISECONDS).build(), new PrimaryShardInfoFutureCache()); - actorContext.broadcast(new TestMessage()); + actorContext.broadcast(new Function() { + @Override + public Object apply(Short v) { + return new TestMessage(); + } + }); MessageCollectorActor.expectFirstMatching(shardActorRef1, TestMessage.class); MessageCollectorActor.expectFirstMatching(shardActorRef2, TestMessage.class); -- 2.36.6