ClusterView { @Override public String toString() { return "a ClusterView[" + json + "]"; } ClusterView(final long viewSeqNum, final boolean viewFinal, final String clusterId, final int localId,
            final Set<Integer> activeIds, final Set<Integer> deactivatingIds, final Set<Integer> inactiveIds); @Override String toString();  }
@Test public void testConstructor() throws Exception { final Integer viewId = 3; final String clusterViewId = UUID.randomUUID().toString(); final Integer instanceId = 2; final Set<Integer> emptyInstanceIds = new HashSet<Integer>(); final Set<Integer> instanceIds = new HashSet<Integer>(); instanceIds.add(1); final Set<Integer> deactivating = new HashSet<Integer>(); final Set<Integer> inactive = new HashSet<Integer>(); try { new ClusterView(-1, true, clusterViewId, instanceId, instanceIds, deactivating, inactive); fail("should complain"); } catch (IllegalStateException e) { } try { new ClusterView(viewId, true, null, instanceId, instanceIds, deactivating, inactive); fail("should complain"); } catch (IllegalStateException e) { } try { new ClusterView(viewId, true, clusterViewId, -1, instanceIds, deactivating, inactive); fail("should complain"); } catch (IllegalStateException e) { } try { new ClusterView(viewId, true, clusterViewId, instanceId, emptyInstanceIds, deactivating, inactive); fail("should complain"); } catch (IllegalStateException e) { } try { new ClusterView(viewId, true, clusterViewId, instanceId, null, deactivating, inactive); fail("should complain"); } catch (IllegalStateException e) { } try { new ClusterView(viewId, true, clusterViewId, instanceId, instanceIds, null, inactive); fail("should complain"); } catch (Exception e) { } try { new ClusterView(viewId, true, clusterViewId, instanceId, instanceIds, deactivating, null); fail("should complain"); } catch (Exception e) { } final Set<Integer> nonEmptyDeactivating = new HashSet<Integer>(); nonEmptyDeactivating.add(3); new ClusterView(viewId, false, clusterViewId, instanceId, instanceIds, nonEmptyDeactivating, inactive); new ClusterView(viewId, true, clusterViewId, instanceId, instanceIds, nonEmptyDeactivating, inactive); new ClusterView(viewId, true, clusterViewId, instanceId, instanceIds, deactivating, inactive); }
@Test public void testOneActiveOnly() throws Exception { String clusterId = UUID.randomUUID().toString(); ClusterViewBuilder builder = new ClusterViewBuilder(10, 21); ClusterView view = builder.active(21).asView(clusterId); JsonObject o = asJsonObject(view); Map<String, String> props = o.getProperties(); assertEquals("10", props.get("seq")); assertEquals(clusterId, unwrapString(props.get("id"))); assertEquals("21", props.get("me")); assertEquals(asJsonArray(21), props.get("active")); assertEquals(asJsonArray(), props.get("deactivating")); assertEquals(asJsonArray(), props.get("inactive")); }
@Test public void testOneActiveOneInactive() throws Exception { String clusterId = UUID.randomUUID().toString(); ClusterViewBuilder builder = new ClusterViewBuilder(10, 2); ClusterView view = builder.active(2).inactive(3).asView(clusterId); JsonObject o = asJsonObject(view); Map<String, String> props = o.getProperties(); assertEquals("10", props.get("seq")); assertEquals(clusterId, unwrapString(props.get("id"))); assertEquals("2", props.get("me")); assertEquals(asJsonArray(2), props.get("active")); assertEquals(asJsonArray(), props.get("deactivating")); assertEquals(asJsonArray(3), props.get("inactive")); }
@Test public void testSeveralActiveOneInactive() throws Exception { String clusterId = UUID.randomUUID().toString(); ClusterViewBuilder builder = new ClusterViewBuilder(10, 2); ClusterView view = builder.active(2, 5, 6).inactive(3).asView(clusterId); JsonObject o = asJsonObject(view); Map<String, String> props = o.getProperties(); assertEquals("10", props.get("seq")); assertEquals("true", props.get("final")); assertEquals(clusterId, unwrapString(props.get("id"))); assertEquals("2", props.get("me")); assertEquals(asJsonArray(2, 5, 6), props.get("active")); assertEquals(asJsonArray(), props.get("deactivating")); assertEquals(asJsonArray(3), props.get("inactive")); }
@Test public void testOneActiveSeveralInactive() throws Exception { String clusterId = UUID.randomUUID().toString(); ClusterViewBuilder builder = new ClusterViewBuilder(10, 2); ClusterView view = builder.active(2).inactive(3, 4, 5, 6).asView(clusterId); JsonObject o = asJsonObject(view); Map<String, String> props = o.getProperties(); assertEquals("10", props.get("seq")); assertEquals("true", props.get("final")); assertEquals(clusterId, unwrapString(props.get("id"))); assertEquals("2", props.get("me")); assertEquals(asJsonArray(2), props.get("active")); assertEquals(asJsonArray(), props.get("deactivating")); assertEquals(asJsonArray(3, 4, 5, 6), props.get("inactive")); }
@Test public void testWithRecoveringOnly() throws Exception { String clusterId = UUID.randomUUID().toString(); ClusterViewBuilder builder = new ClusterViewBuilder(10, 2); ClusterView view = builder.active(2, 3).recovering(4).inactive(5, 6).asView(clusterId); JsonObject o = asJsonObject(view); Map<String, String> props = o.getProperties(); assertEquals("10", props.get("seq")); assertEquals("true", props.get("final")); assertEquals(clusterId, unwrapString(props.get("id"))); assertEquals("2", props.get("me")); assertEquals(asJsonArray(2, 3), props.get("active")); assertEquals(asJsonArray(4), props.get("deactivating")); assertEquals(asJsonArray(5, 6), props.get("inactive")); }
@Test public void testWithRecoveringAndBacklog() throws Exception { String clusterId = UUID.randomUUID().toString(); ClusterViewBuilder builder = new ClusterViewBuilder(10, 2); ClusterView view = builder.active(2, 3).recovering(4).inactive(5, 6).backlogs(5).asView(clusterId); JsonObject o = asJsonObject(view); Map<String, String> props = o.getProperties(); assertEquals("10", props.get("seq")); assertEquals(clusterId, unwrapString(props.get("id"))); assertEquals("2", props.get("me")); assertEquals("false", props.get("final")); assertEquals(asJsonArray(2, 3), props.get("active")); assertEquals(asJsonArray(4, 5), props.get("deactivating")); assertEquals(asJsonArray(6), props.get("inactive")); }
@Test public void testBacklogButNotInactive() throws Exception { String clusterId = UUID.randomUUID().toString(); ClusterViewBuilder builder = new ClusterViewBuilder(10, 2); try { ClusterView view = builder.active(2, 3).backlogs(5).asView(clusterId); fail("should complain"); } catch (Exception ok) { } }