GEODE-3072: Changed getMembershipId to use the client version
Project: http://git-wip-us.apache.org/repos/asf/geode/repo Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/dd90c71d Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/dd90c71d Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/dd90c71d Branch: refs/heads/feature/GEODE-3071 Commit: dd90c71d036d9d28b8c593ab8cbae57357a64b03 Parents: a21c971 Author: Barry Oglesby <bogle...@pivotal.io> Authored: Tue Jun 13 18:18:19 2017 -0700 Committer: Barry Oglesby <bogle...@pivotal.io> Committed: Thu Jun 15 09:19:36 2017 -0700 ---------------------------------------------------------------------- .../apache/geode/internal/cache/EventID.java | 2 +- .../sockets/ClientServerMiscBCDUnitTest.java | 40 ++++++++++++++++++++ .../tier/sockets/ClientServerMiscDUnitTest.java | 4 +- 3 files changed, 43 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/geode/blob/dd90c71d/geode-core/src/main/java/org/apache/geode/internal/cache/EventID.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/EventID.java b/geode-core/src/main/java/org/apache/geode/internal/cache/EventID.java index 71acdc9..4d2ddc1 100755 --- a/geode-core/src/main/java/org/apache/geode/internal/cache/EventID.java +++ b/geode-core/src/main/java/org/apache/geode/internal/cache/EventID.java @@ -164,7 +164,7 @@ public class EventID implements DataSerializableFixedID, Serializable, Externali */ public static byte[] getMembershipId(ClientProxyMembershipID client) { try { - HeapDataOutputStream hdos = new HeapDataOutputStream(256, Version.CURRENT); + HeapDataOutputStream hdos = new HeapDataOutputStream(256, client.getClientVersion()); ((InternalDistributedMember) client.getDistributedMember()).writeEssentialData(hdos); return hdos.toByteArray(); } catch (IOException ioe) { http://git-wip-us.apache.org/repos/asf/geode/blob/dd90c71d/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ClientServerMiscBCDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ClientServerMiscBCDUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ClientServerMiscBCDUnitTest.java index d51c196..c732662 100755 --- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ClientServerMiscBCDUnitTest.java +++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ClientServerMiscBCDUnitTest.java @@ -14,10 +14,13 @@ */ package org.apache.geode.internal.cache.tier.sockets; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import org.apache.geode.cache.Region; import org.apache.geode.cache.client.Pool; +import org.apache.geode.internal.cache.EventID; import org.apache.geode.internal.cache.LocalRegion; import org.apache.geode.test.dunit.Host; import org.apache.geode.test.dunit.NetworkUtils; @@ -33,8 +36,10 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; +import java.util.Arrays; import java.util.Collection; import java.util.List; +import java.util.Set; import java.util.concurrent.TimeUnit; @Category({DistributedTest.class, ClientServerTest.class, BackwardCompatibilityTest.class}) @@ -90,4 +95,39 @@ public class ClientServerMiscBCDUnitTest extends ClientServerMiscDUnitTest { }); } + @Test + public void testDistributedMemberBytesWithCurrentServerAndOldClient() throws Exception { + // Start current version server + int serverPort = initServerCache(true); + + // Start old version client and do puts + VM client = Host.getHost(0).getVM(testVersion, 1); + String hostname = NetworkUtils.getServerHostName(Host.getHost(0)); + client.invoke("create client cache", () -> { + createClientCache(hostname, serverPort); + populateCache(); + }); + + // Get client member id byte array on client + byte[] clientMembershipIdBytesOnClient = + client.invoke(() -> getClientMembershipIdBytesOnClient()); + + // Get client member id byte array on server + byte[] clientMembershipIdBytesOnServer = + server1.invoke(() -> getClientMembershipIdBytesOnServer()); + + // Verify member id bytes on client and server are equal + assertTrue(Arrays.equals(clientMembershipIdBytesOnClient, clientMembershipIdBytesOnServer)); + } + + private byte[] getClientMembershipIdBytesOnClient() { + return EventID.getMembershipId(getCache().getDistributedSystem()); + } + + private byte[] getClientMembershipIdBytesOnServer() { + Set cpmIds = ClientHealthMonitor.getInstance().getClientHeartbeats().keySet(); + assertEquals(1, cpmIds.size()); + ClientProxyMembershipID cpmId = (ClientProxyMembershipID) cpmIds.iterator().next(); + return EventID.getMembershipId(cpmId); + } } http://git-wip-us.apache.org/repos/asf/geode/blob/dd90c71d/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ClientServerMiscDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ClientServerMiscDUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ClientServerMiscDUnitTest.java index bbaea9d..bfe4646 100755 --- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ClientServerMiscDUnitTest.java +++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ClientServerMiscDUnitTest.java @@ -110,9 +110,9 @@ public class ClientServerMiscDUnitTest extends JUnit4CacheTestCase { private static Host host; - private static VM server1; + protected static VM server1; - private static VM server2; + protected static VM server2; private static RegionAttributes attrs;