@Test public void testClusterInitialization() { try { Cluster cluster = defaultFactory.getCluster("Cluster Un"); assertNotNull("Test cluster should not be null", cluster); // now check that it has the data we expect from the database assertEquals("Wrong ID Found", 1000L, cluster.getId()); assertEquals("Wrong name found", "Cluster Un", cluster.getName()); // Now check for the master node Node master = cluster.getMaster(); assertNotNull("Master node for cluster should not be null", master); assertEquals( "Unexpected name for master found", "Cluster 0 - Primary master", master.getName()); assertEquals("Unexpected ID for master found", 1L, master.getId()); assertTrue("Master should be available", master.isAvailable()); // Now check for the slave nodes Set<Node> slaves = cluster.getSlaves(); assertNotNull("Slave node set should not be null", slaves); assertEquals("Unexpected length for slave node set", 2, slaves.size()); } catch (Exception e) { e.printStackTrace(); fail("Exception caught: " + e.getLocalizedMessage()); } }
/** Tests whether the ClusterFactory creates more than one cluster for a given name */ @Test public void testSingletonClusterInstances() { // first test the default Cluster cluster = defaultFactory.getCluster(ClusterFactory.DEFAULT_CLUSTER_NAME); assertSame( "PersistentClusterFactory should only create one instance for a given cluster", cluster, defaultFactory.getCluster(ClusterFactory.DEFAULT_CLUSTER_NAME)); // Then test for a custom name cluster = defaultFactory.getCluster("FOOBAR"); assertSame( "PersistentClusterFactory should only create one instance for a given cluster", cluster, defaultFactory.getCluster("FOOBAR")); }
@Test public void testNullName() { try { Cluster cluster = defaultFactory.getCluster(null); fail("Cluster initialization should fail with a null name"); } catch (Exception e) { assertTrue(e instanceof ClusterInitializationException); } }
@Test public void testDefaultCluster() { // Test that we get what we expect whit the default cluster Cluster cluster = defaultFactory.getCluster(ClusterFactory.DEFAULT_CLUSTER_NAME); assertNotNull("Cluster should not be null", cluster); assertEquals( "Unexpected default Cluster instance", ClusterFactory.DEFAULT_CLUSTER_NAME, cluster.getName()); }
public static final ClusterFactory getClusterFactory() { ClusterFactory factory = null; try { factory = ClusterFactory.getClusterFactory(); } catch (Exception e) { e.printStackTrace(); fail("Cannot create defaultFactory: " + e.getLocalizedMessage()); } assertNotNull("Cannot instantiate defaultFactory", factory); return factory; }