@Test public void checkRpcVersions() throws Exception { RpcVersionsCheckResult checkResult = RpcProtocolVersionsUtil.checkRpcProtocolVersions( RpcProtocolVersions.newBuilder() .setMaxRpcVersion(Version.newBuilder().setMajor(3).setMinor(2).build()) .setMinRpcVersion(Version.newBuilder().setMajor(2).setMinor(1).build()) .build(), RpcProtocolVersions.newBuilder() .setMaxRpcVersion(Version.newBuilder().setMajor(2).setMinor(1).build()) .setMinRpcVersion(Version.newBuilder().setMajor(1).setMinor(2).build()) .build()); assertTrue(checkResult.getResult()); assertEquals( Version.newBuilder().setMajor(2).setMinor(1).build(), checkResult.getHighestCommonVersion()); checkResult = RpcProtocolVersionsUtil.checkRpcProtocolVersions( RpcProtocolVersions.newBuilder() .setMaxRpcVersion(Version.newBuilder().setMajor(3).setMinor(2).build()) .setMinRpcVersion(Version.newBuilder().setMajor(1).setMinor(2).build()) .build(), RpcProtocolVersions.newBuilder() .setMaxRpcVersion(Version.newBuilder().setMajor(2).setMinor(1).build()) .setMinRpcVersion(Version.newBuilder().setMajor(2).setMinor(1).build()) .build()); assertTrue(checkResult.getResult()); assertEquals( Version.newBuilder().setMajor(2).setMinor(1).build(), checkResult.getHighestCommonVersion()); checkResult = RpcProtocolVersionsUtil.checkRpcProtocolVersions( RpcProtocolVersions.newBuilder() .setMaxRpcVersion(Version.newBuilder().setMajor(3).setMinor(2).build()) .setMinRpcVersion(Version.newBuilder().setMajor(2).setMinor(1).build()) .build(), RpcProtocolVersions.newBuilder() .setMaxRpcVersion(Version.newBuilder().setMajor(2).setMinor(1).build()) .setMinRpcVersion(Version.newBuilder().setMajor(2).setMinor(1).build()) .build()); assertTrue(checkResult.getResult()); assertEquals( Version.newBuilder().setMajor(2).setMinor(1).build(), checkResult.getHighestCommonVersion()); checkResult = RpcProtocolVersionsUtil.checkRpcProtocolVersions( RpcProtocolVersions.newBuilder() .setMaxRpcVersion(Version.newBuilder().setMajor(2).setMinor(1).build()) .setMinRpcVersion(Version.newBuilder().setMajor(2).setMinor(1).build()) .build(), RpcProtocolVersions.newBuilder() .setMaxRpcVersion(Version.newBuilder().setMajor(3).setMinor(2).build()) .setMinRpcVersion(Version.newBuilder().setMajor(1).setMinor(2).build()) .build()); assertTrue(checkResult.getResult()); assertEquals( Version.newBuilder().setMajor(2).setMinor(1).build(), checkResult.getHighestCommonVersion()); checkResult = RpcProtocolVersionsUtil.checkRpcProtocolVersions( RpcProtocolVersions.newBuilder() .setMaxRpcVersion(Version.newBuilder().setMajor(2).setMinor(1).build()) .setMinRpcVersion(Version.newBuilder().setMajor(2).setMinor(1).build()) .build(), RpcProtocolVersions.newBuilder() .setMaxRpcVersion(Version.newBuilder().setMajor(2).setMinor(1).build()) .setMinRpcVersion(Version.newBuilder().setMajor(1).setMinor(2).build()) .build()); assertTrue(checkResult.getResult()); assertEquals( Version.newBuilder().setMajor(2).setMinor(1).build(), checkResult.getHighestCommonVersion()); checkResult = RpcProtocolVersionsUtil.checkRpcProtocolVersions( RpcProtocolVersions.newBuilder() .setMaxRpcVersion(Version.newBuilder().setMajor(2).setMinor(1).build()) .setMinRpcVersion(Version.newBuilder().setMajor(1).setMinor(2).build()) .build(), RpcProtocolVersions.newBuilder() .setMaxRpcVersion(Version.newBuilder().setMajor(3).setMinor(2).build()) .setMinRpcVersion(Version.newBuilder().setMajor(2).setMinor(1).build()) .build()); assertTrue(checkResult.getResult()); assertEquals( Version.newBuilder().setMajor(2).setMinor(1).build(), checkResult.getHighestCommonVersion()); checkResult = RpcProtocolVersionsUtil.checkRpcProtocolVersions( RpcProtocolVersions.newBuilder() .setMaxRpcVersion(Version.newBuilder().setMajor(2).setMinor(1).build()) .setMinRpcVersion(Version.newBuilder().setMajor(1).setMinor(2).build()) .build(), RpcProtocolVersions.newBuilder() .setMaxRpcVersion(Version.newBuilder().setMajor(3).setMinor(2).build()) .setMinRpcVersion(Version.newBuilder().setMajor(1).setMinor(2).build()) .build()); assertTrue(checkResult.getResult()); assertEquals( Version.newBuilder().setMajor(2).setMinor(1).build(), checkResult.getHighestCommonVersion()); checkResult = RpcProtocolVersionsUtil.checkRpcProtocolVersions( RpcProtocolVersions.newBuilder() .setMaxRpcVersion(Version.newBuilder().setMajor(2).setMinor(1).build()) .setMinRpcVersion(Version.newBuilder().setMajor(1).setMinor(2).build()) .build(), RpcProtocolVersions.newBuilder() .setMaxRpcVersion(Version.newBuilder().setMajor(2).setMinor(1).build()) .setMinRpcVersion(Version.newBuilder().setMajor(1).setMinor(2).build()) .build()); assertTrue(checkResult.getResult()); assertEquals( Version.newBuilder().setMajor(2).setMinor(1).build(), checkResult.getHighestCommonVersion()); checkResult = RpcProtocolVersionsUtil.checkRpcProtocolVersions( RpcProtocolVersions.newBuilder() .setMaxRpcVersion(Version.newBuilder().setMajor(2).setMinor(1).build()) .setMinRpcVersion(Version.newBuilder().setMajor(2).setMinor(1).build()) .build(), RpcProtocolVersions.newBuilder() .setMaxRpcVersion(Version.newBuilder().setMajor(2).setMinor(1).build()) .setMinRpcVersion(Version.newBuilder().setMajor(2).setMinor(1).build()) .build()); assertTrue(checkResult.getResult()); assertEquals( Version.newBuilder().setMajor(2).setMinor(1).build(), checkResult.getHighestCommonVersion()); checkResult = RpcProtocolVersionsUtil.checkRpcProtocolVersions( RpcProtocolVersions.newBuilder() .setMaxRpcVersion(Version.newBuilder().setMajor(1).setMinor(2).build()) .setMinRpcVersion(Version.newBuilder().setMajor(2).setMinor(1).build()) .build(), RpcProtocolVersions.newBuilder() .setMaxRpcVersion(Version.newBuilder().setMajor(1).setMinor(2).build()) .setMinRpcVersion(Version.newBuilder().setMajor(2).setMinor(1).build()) .build()); assertFalse(checkResult.getResult()); assertEquals(null, checkResult.getHighestCommonVersion()); checkResult = RpcProtocolVersionsUtil.checkRpcProtocolVersions( RpcProtocolVersions.newBuilder() .setMaxRpcVersion(Version.newBuilder().setMajor(6).setMinor(5).build()) .setMinRpcVersion(Version.newBuilder().setMajor(4).setMinor(3).build()) .build(), RpcProtocolVersions.newBuilder() .setMaxRpcVersion(Version.newBuilder().setMajor(2).setMinor(1).build()) .setMinRpcVersion(Version.newBuilder().setMajor(0).setMinor(0).build()) .build()); assertFalse(checkResult.getResult()); assertEquals(null, checkResult.getHighestCommonVersion()); checkResult = RpcProtocolVersionsUtil.checkRpcProtocolVersions( RpcProtocolVersions.newBuilder() .setMaxRpcVersion(Version.newBuilder().setMajor(2).setMinor(1).build()) .setMinRpcVersion(Version.newBuilder().setMajor(1).setMinor(0).build()) .build(), RpcProtocolVersions.newBuilder() .setMaxRpcVersion(Version.newBuilder().setMajor(6).setMinor(5).build()) .setMinRpcVersion(Version.newBuilder().setMajor(4).setMinor(3).build()) .build()); assertFalse(checkResult.getResult()); assertEquals(null, checkResult.getHighestCommonVersion()); checkResult = RpcProtocolVersionsUtil.checkRpcProtocolVersions( RpcProtocolVersions.newBuilder() .setMaxRpcVersion(Version.newBuilder().setMajor(4).setMinor(3).build()) .setMinRpcVersion(Version.newBuilder().setMajor(6).setMinor(5).build()) .build(), RpcProtocolVersions.newBuilder() .setMaxRpcVersion(Version.newBuilder().setMajor(1).setMinor(0).build()) .setMinRpcVersion(Version.newBuilder().setMajor(2).setMinor(1).build()) .build()); assertFalse(checkResult.getResult()); assertEquals(null, checkResult.getHighestCommonVersion()); }
static RpcVersionsCheckResult checkRpcProtocolVersions( RpcProtocolVersions localVersions, RpcProtocolVersions peerVersions) { Version maxCommonVersion; Version minCommonVersion; if (isGreaterThanOrEqualTo(localVersions.getMaxRpcVersion(), peerVersions.getMaxRpcVersion())) { maxCommonVersion = peerVersions.getMaxRpcVersion(); } else { maxCommonVersion = localVersions.getMaxRpcVersion(); } if (isGreaterThanOrEqualTo(localVersions.getMinRpcVersion(), peerVersions.getMinRpcVersion())) { minCommonVersion = localVersions.getMinRpcVersion(); } else { minCommonVersion = peerVersions.getMinRpcVersion(); } if (isGreaterThanOrEqualTo(maxCommonVersion, minCommonVersion)) { return new RpcVersionsCheckResult.Builder() .setResult(true) .setHighestCommonVersion(maxCommonVersion) .build(); } return new RpcVersionsCheckResult.Builder().setResult(false).build(); }
RpcProtocolVersionsUtil { static RpcVersionsCheckResult checkRpcProtocolVersions( RpcProtocolVersions localVersions, RpcProtocolVersions peerVersions) { Version maxCommonVersion; Version minCommonVersion; if (isGreaterThanOrEqualTo(localVersions.getMaxRpcVersion(), peerVersions.getMaxRpcVersion())) { maxCommonVersion = peerVersions.getMaxRpcVersion(); } else { maxCommonVersion = localVersions.getMaxRpcVersion(); } if (isGreaterThanOrEqualTo(localVersions.getMinRpcVersion(), peerVersions.getMinRpcVersion())) { minCommonVersion = localVersions.getMinRpcVersion(); } else { minCommonVersion = peerVersions.getMinRpcVersion(); } if (isGreaterThanOrEqualTo(maxCommonVersion, minCommonVersion)) { return new RpcVersionsCheckResult.Builder() .setResult(true) .setHighestCommonVersion(maxCommonVersion) .build(); } return new RpcVersionsCheckResult.Builder().setResult(false).build(); } }
RpcProtocolVersionsUtil { static RpcVersionsCheckResult checkRpcProtocolVersions( RpcProtocolVersions localVersions, RpcProtocolVersions peerVersions) { Version maxCommonVersion; Version minCommonVersion; if (isGreaterThanOrEqualTo(localVersions.getMaxRpcVersion(), peerVersions.getMaxRpcVersion())) { maxCommonVersion = peerVersions.getMaxRpcVersion(); } else { maxCommonVersion = localVersions.getMaxRpcVersion(); } if (isGreaterThanOrEqualTo(localVersions.getMinRpcVersion(), peerVersions.getMinRpcVersion())) { minCommonVersion = localVersions.getMinRpcVersion(); } else { minCommonVersion = peerVersions.getMinRpcVersion(); } if (isGreaterThanOrEqualTo(maxCommonVersion, minCommonVersion)) { return new RpcVersionsCheckResult.Builder() .setResult(true) .setHighestCommonVersion(maxCommonVersion) .build(); } return new RpcVersionsCheckResult.Builder().setResult(false).build(); }  }
RpcProtocolVersionsUtil { static RpcVersionsCheckResult checkRpcProtocolVersions( RpcProtocolVersions localVersions, RpcProtocolVersions peerVersions) { Version maxCommonVersion; Version minCommonVersion; if (isGreaterThanOrEqualTo(localVersions.getMaxRpcVersion(), peerVersions.getMaxRpcVersion())) { maxCommonVersion = peerVersions.getMaxRpcVersion(); } else { maxCommonVersion = localVersions.getMaxRpcVersion(); } if (isGreaterThanOrEqualTo(localVersions.getMinRpcVersion(), peerVersions.getMinRpcVersion())) { minCommonVersion = localVersions.getMinRpcVersion(); } else { minCommonVersion = peerVersions.getMinRpcVersion(); } if (isGreaterThanOrEqualTo(maxCommonVersion, minCommonVersion)) { return new RpcVersionsCheckResult.Builder() .setResult(true) .setHighestCommonVersion(maxCommonVersion) .build(); } return new RpcVersionsCheckResult.Builder().setResult(false).build(); }  static RpcProtocolVersions getRpcProtocolVersions(); }
RpcProtocolVersionsUtil { static RpcVersionsCheckResult checkRpcProtocolVersions( RpcProtocolVersions localVersions, RpcProtocolVersions peerVersions) { Version maxCommonVersion; Version minCommonVersion; if (isGreaterThanOrEqualTo(localVersions.getMaxRpcVersion(), peerVersions.getMaxRpcVersion())) { maxCommonVersion = peerVersions.getMaxRpcVersion(); } else { maxCommonVersion = localVersions.getMaxRpcVersion(); } if (isGreaterThanOrEqualTo(localVersions.getMinRpcVersion(), peerVersions.getMinRpcVersion())) { minCommonVersion = localVersions.getMinRpcVersion(); } else { minCommonVersion = peerVersions.getMinRpcVersion(); } if (isGreaterThanOrEqualTo(maxCommonVersion, minCommonVersion)) { return new RpcVersionsCheckResult.Builder() .setResult(true) .setHighestCommonVersion(maxCommonVersion) .build(); } return new RpcVersionsCheckResult.Builder().setResult(false).build(); }  static RpcProtocolVersions getRpcProtocolVersions();  }