ZNRecord record = new ZNRecord("TESTDB");
// one master
add(record, "TESTDB_0", "localhost_8900", "MASTER");
List<ExternalView> externalViewList = new ArrayList<ExternalView>();
externalViewList.add(new ExternalView(record));
routingTable.onExternalViewChange(externalViewList, changeContext);
instances = routingTable.getInstances("TESTDB", "TESTDB_0", "MASTER");
AssertJUnit.assertNotNull(instances);
AssertJUnit.assertEquals(instances.size(), 1);
// additions
add(record, "TESTDB_0", "localhost_8901", "MASTER");
add(record, "TESTDB_1", "localhost_8900", "SLAVE");
externalViewList = new ArrayList<ExternalView>();
externalViewList.add(new ExternalView(record));
routingTable.onExternalViewChange(externalViewList, changeContext);
instances = routingTable.getInstances("TESTDB", "TESTDB_0", "MASTER");
AssertJUnit.assertNotNull(instances);
AssertJUnit.assertEquals(instances.size(), 2);
instances = routingTable.getInstances("TESTDB", "TESTDB_1", "SLAVE");
AssertJUnit.assertNotNull(instances);
AssertJUnit.assertEquals(instances.size(), 1);
// updates
add(record, "TESTDB_0", "localhost_8901", "SLAVE");
externalViewList = new ArrayList<ExternalView>();
externalViewList.add(new ExternalView(record));
routingTable.onExternalViewChange(externalViewList, changeContext);
instances = routingTable.getInstances("TESTDB", "TESTDB_0", "SLAVE");
AssertJUnit.assertNotNull(instances);
AssertJUnit.assertEquals(instances.size(), 1);
}