// DNode1 enters with partitions t1/1/0 and t1/2/0
ctx.updateTablespaceVersions(facade1.getDNodeInfo(), DNodeEvent.ENTRY);
assertEquals(2, ctx.getTablespaceVersionsMap().keySet().size());
Tablespace tablespaceV1 = ctx.getTablespaceVersionsMap().get(new TablespaceVersion("t1", 1l));
Tablespace tablespaceV2 = ctx.getTablespaceVersionsMap().get(new TablespaceVersion("t1", 2l));
assertTablespace(tablespaceV1, new Integer[] { 0 }, "dnode1");
assertTablespace(tablespaceV2, new Integer[] { 0 }, "dnode1");
// DNode2 enters with partitions t1/1/0 and t1/2/1
// DNode2 enters with partitions t1/3/0 and t2/1/0 too
DNodeInfoFacade facade2 = new DNodeInfoFacade("dnode2");
facade2.addTablespaceVersionPartition("t1", 1l, 0);
facade2.addTablespaceVersionPartition("t1", 2l, 1);
facade2.addTablespaceVersionPartition("t1", 3l, 0);
facade2.addTablespaceVersionPartition("t2", 1l, 0);
ctx.updateTablespaceVersions(facade2.getDNodeInfo(), DNodeEvent.ENTRY);
Tablespace tablespace1V1 = ctx.getTablespaceVersionsMap().get(new TablespaceVersion("t1", 1l));
Tablespace tablespace1V2 = ctx.getTablespaceVersionsMap().get(new TablespaceVersion("t1", 2l));
Tablespace tablespace1V3 = ctx.getTablespaceVersionsMap().get(new TablespaceVersion("t1", 3l));
Tablespace tablespace2V1 = ctx.getTablespaceVersionsMap().get(new TablespaceVersion("t2", 1l));
assertTablespace(tablespace1V1, new Integer[] { 0, 0 }, "dnode1", "dnode2");
assertTablespace(tablespace1V2, new Integer[] { 0, 1 }, "dnode1", "dnode2");
assertTablespace(tablespace1V3, new Integer[] { 0 }, "dnode2");
assertTablespace(tablespace2V1, new Integer[] { 0 }, "dnode2");
// DNode3 enters with partitions t1/1/1 and t2/2/1
DNodeInfoFacade facade3 = new DNodeInfoFacade("dnode3");
facade3.addTablespaceVersionPartition("t1", 1l, 1);
facade3.addTablespaceVersionPartition("t2", 1l, 1);
ctx.updateTablespaceVersions(facade3.getDNodeInfo(), DNodeEvent.ENTRY);
tablespace1V1 = ctx.getTablespaceVersionsMap().get(new TablespaceVersion("t1", 1l));
tablespace1V2 = ctx.getTablespaceVersionsMap().get(new TablespaceVersion("t1", 2l));
tablespace1V3 = ctx.getTablespaceVersionsMap().get(new TablespaceVersion("t1", 3l));
tablespace2V1 = ctx.getTablespaceVersionsMap().get(new TablespaceVersion("t2", 1l));
assertTablespace(tablespace1V1, new Integer[] { 0, 0, 1 }, "dnode1", "dnode2", "dnode3");
assertTablespace(tablespace1V2, new Integer[] { 0, 1 }, "dnode1", "dnode2");
assertTablespace(tablespace1V3, new Integer[] { 0 }, "dnode2");
assertTablespace(tablespace2V1, new Integer[] { 0, 1 }, "dnode2", "dnode3");
// DNode 2 leaves. Tablespace 1 version 3 becomes empty!
ctx.updateTablespaceVersions(facade2.getDNodeInfo(), DNodeEvent.LEAVE);
tablespace1V1 = ctx.getTablespaceVersionsMap().get(new TablespaceVersion("t1", 1l));
tablespace1V2 = ctx.getTablespaceVersionsMap().get(new TablespaceVersion("t1", 2l));
tablespace1V3 = ctx.getTablespaceVersionsMap().get(new TablespaceVersion("t1", 3l));
tablespace2V1 = ctx.getTablespaceVersionsMap().get(new TablespaceVersion("t2", 1l));
assertNull(tablespace1V3);
assertTablespace(tablespace1V1, new Integer[] { 0, 1 }, "dnode1", "dnode3");
assertTablespace(tablespace1V2, new Integer[] { 0 }, "dnode1");
assertTablespace(tablespace2V1, new Integer[] { 1 }, "dnode3");
// DNode 2 enters again. Assure that things remain the same as before.
ctx.updateTablespaceVersions(facade2.getDNodeInfo(), DNodeEvent.ENTRY);
tablespace1V1 = ctx.getTablespaceVersionsMap().get(new TablespaceVersion("t1", 1l));
tablespace1V2 = ctx.getTablespaceVersionsMap().get(new TablespaceVersion("t1", 2l));
tablespace1V3 = ctx.getTablespaceVersionsMap().get(new TablespaceVersion("t1", 3l));
tablespace2V1 = ctx.getTablespaceVersionsMap().get(new TablespaceVersion("t2", 1l));
assertTablespace(tablespace1V1, new Integer[] { 0, 0, 1 }, "dnode1", "dnode2", "dnode3");
assertTablespace(tablespace1V2, new Integer[] { 0, 1 }, "dnode1", "dnode2");
assertTablespace(tablespace1V3, new Integer[] { 0 }, "dnode2");
assertTablespace(tablespace2V1, new Integer[] { 0, 1 }, "dnode2", "dnode3");
// DNode 2 leaves. DNode 1 leaves.
ctx.updateTablespaceVersions(facade2.getDNodeInfo(), DNodeEvent.LEAVE);
ctx.updateTablespaceVersions(facade1.getDNodeInfo(), DNodeEvent.LEAVE);
tablespace1V1 = ctx.getTablespaceVersionsMap().get(new TablespaceVersion("t1", 1l));
tablespace1V2 = ctx.getTablespaceVersionsMap().get(new TablespaceVersion("t1", 2l));
tablespace1V3 = ctx.getTablespaceVersionsMap().get(new TablespaceVersion("t1", 3l));
tablespace2V1 = ctx.getTablespaceVersionsMap().get(new TablespaceVersion("t2", 1l));
assertTablespace(tablespace1V1, new Integer[] { 1 }, "dnode3");
assertNull(tablespace1V2);
assertNull(tablespace1V3);
assertTablespace(tablespace2V1, new Integer[] { 1 }, "dnode3");
// DNode 3 leaves.
ctx.updateTablespaceVersions(facade3.getDNodeInfo(), DNodeEvent.LEAVE);
tablespace1V1 = ctx.getTablespaceVersionsMap().get(new TablespaceVersion("t1", 1l));
tablespace1V2 = ctx.getTablespaceVersionsMap().get(new TablespaceVersion("t1", 2l));
tablespace1V3 = ctx.getTablespaceVersionsMap().get(new TablespaceVersion("t1", 3l));
tablespace2V1 = ctx.getTablespaceVersionsMap().get(new TablespaceVersion("t2", 1l));
assertNull(tablespace1V1);
assertNull(tablespace1V2);
assertNull(tablespace1V3);
assertNull(tablespace2V1);