@Test public void shouldSeeBalancerStateAfterClusterMembersLeave() throws Exception { DefaultClusterContext clusterContext1 = null; DefaultClusterContext clusterContext2 = null; DefaultClusterContext clusterContext3 = null; DefaultClusterContext clusterContext4 = null; try { MemberId member1 = new MemberId("tcp", "127.0.0.1", 46941); MemberId member2 = new MemberId("tcp", "127.0.0.1", 46942); MemberId member3 = new MemberId("tcp", "127.0.0.1", 46943); MemberId member4 = new MemberId("tcp", "127.0.0.1", 46944); List<MemberId> accepts1 = Collections.singletonList(member1); List<MemberId> connects1 = Arrays.asList(member2, member3, member4); List<MemberId> accepts2 = Collections.singletonList(member2); List<MemberId> connects2 = Arrays.asList(member1, member3, member4); List<MemberId> accepts3 = Collections.singletonList(member3); List<MemberId> connects3 = Arrays.asList(member1, member2, member4); List<MemberId> accepts4 = Collections.singletonList(member4); List<MemberId> connects4 = Arrays.asList(member1, member2, member3); final String clusterName = this.getClass().getName() + "-cluster1"; clusterContext1 = new DefaultClusterContext(clusterName, accepts1, connects1, new Properties()); clusterContext2 = new DefaultClusterContext(clusterName, accepts2, connects2, new Properties()); clusterContext3 = new DefaultClusterContext(clusterName, accepts3, connects3, new Properties()); clusterContext4 = new DefaultClusterContext(clusterName, accepts4, connects4, new Properties()); Map<ClusterContext, String> expectedBalancedServicesUrlsMap = new HashMap<>(); initClusterContext(clusterContext1, expectedBalancedServicesUrlsMap, 1); try { Thread.sleep(2000); } catch (Exception ex) { } initClusterContext(clusterContext2, expectedBalancedServicesUrlsMap, 2); initClusterContext(clusterContext3, expectedBalancedServicesUrlsMap, 3); initClusterContext(clusterContext4, expectedBalancedServicesUrlsMap, 4); validateClusterState(Arrays.asList(clusterContext1, clusterContext2, clusterContext3, clusterContext4), expectedBalancedServicesUrlsMap); clusterContext1.dispose(); clusterContext2.dispose(); expectedBalancedServicesUrlsMap.remove(clusterContext1); expectedBalancedServicesUrlsMap.remove(clusterContext2); validateClusterState(Arrays.asList(clusterContext3, clusterContext4), expectedBalancedServicesUrlsMap); clusterContext1 = new DefaultClusterContext(clusterName, accepts1, connects1, null); clusterContext2 = new DefaultClusterContext(clusterName, accepts2, connects2, null); initClusterContext(clusterContext1, expectedBalancedServicesUrlsMap, 1); initClusterContext(clusterContext2, expectedBalancedServicesUrlsMap, 2); validateClusterState(Arrays.asList(clusterContext1, clusterContext2, clusterContext3, clusterContext4), expectedBalancedServicesUrlsMap); } finally { if (clusterContext1 != null) { clusterContext1.dispose(); } if (clusterContext2 != null) { clusterContext2.dispose(); } if (clusterContext3 != null) { clusterContext3.dispose(); } if (clusterContext4 != null) { clusterContext4.dispose(); } } }
@Override public void dispose() { if (clusterInstance != null) { clusterInstance.getLifecycleService().shutdown(); } }
DefaultClusterContext implements ClusterContext, LogListener { @Override public void dispose() { if (clusterInstance != null) { clusterInstance.getLifecycleService().shutdown(); } } }
DefaultClusterContext implements ClusterContext, LogListener { @Override public void dispose() { if (clusterInstance != null) { clusterInstance.getLifecycleService().shutdown(); } } DefaultClusterContext(String name,
                                 List<MemberId> interfaces,
                                 List<MemberId> members,
                                 Properties gatewayConfiguration);  DefaultClusterContext(String name,
                                 List<MemberId> interfaces,
                                 List<MemberId> members,
                                 ClusterConnectOptionsContext connectOptions,
                                 Properties gatewayConfiguration); }
DefaultClusterContext implements ClusterContext, LogListener { @Override public void dispose() { if (clusterInstance != null) { clusterInstance.getLifecycleService().shutdown(); } } DefaultClusterContext(String name,
                                 List<MemberId> interfaces,
                                 List<MemberId> members,
                                 Properties gatewayConfiguration);  DefaultClusterContext(String name,
                                 List<MemberId> interfaces,
                                 List<MemberId> members,
                                 ClusterConnectOptionsContext connectOptions,
                                 Properties gatewayConfiguration); @Override void start(); @Override void dispose(); @Override MemberId getLocalMember(); @Override Collection<MemberId> getMemberIds(); @Override String getInstanceKey(MemberId memberId); @Override Lock getLock(String name); @Override void addMembershipEventListener(MembershipEventListener eventListener); @Override void removeMembershipEventListener(MembershipEventListener eventListener); @Override String getClusterName(); @Override List<MemberId> getAccepts(); @Override List<MemberId> getConnects(); @Override ClusterConnectOptionsContext getConnectOptions(); @Override /* * Logs cluster state and balancer service maps contents when ha logging is enabled at trace level ! */ void logClusterState(); @Override /* * Logs cluster state at Info Level, recommended use only for startup or methods that are called only one time when * cluster state changes ! */ void logClusterStateAtInfoLevel(); @Override CollectionsFactory getCollectionsFactory(); @Override void log(LogEvent logEvent); @Override ITopic<E> getTopic(String name); }
DefaultClusterContext implements ClusterContext, LogListener { @Override public void dispose() { if (clusterInstance != null) { clusterInstance.getLifecycleService().shutdown(); } } DefaultClusterContext(String name,
                                 List<MemberId> interfaces,
                                 List<MemberId> members,
                                 Properties gatewayConfiguration);  DefaultClusterContext(String name,
                                 List<MemberId> interfaces,
                                 List<MemberId> members,
                                 ClusterConnectOptionsContext connectOptions,
                                 Properties gatewayConfiguration); @Override void start(); @Override void dispose(); @Override MemberId getLocalMember(); @Override Collection<MemberId> getMemberIds(); @Override String getInstanceKey(MemberId memberId); @Override Lock getLock(String name); @Override void addMembershipEventListener(MembershipEventListener eventListener); @Override void removeMembershipEventListener(MembershipEventListener eventListener); @Override String getClusterName(); @Override List<MemberId> getAccepts(); @Override List<MemberId> getConnects(); @Override ClusterConnectOptionsContext getConnectOptions(); @Override /* * Logs cluster state and balancer service maps contents when ha logging is enabled at trace level ! */ void logClusterState(); @Override /* * Logs cluster state at Info Level, recommended use only for startup or methods that are called only one time when * cluster state changes ! */ void logClusterStateAtInfoLevel(); @Override CollectionsFactory getCollectionsFactory(); @Override void log(LogEvent logEvent); @Override ITopic<E> getTopic(String name);  }