use of org.neo4j.kernel.ha.com.master.SlaveFactory in project neo4j by neo4j.
the class HighAvailabilitySlavesTest method shouldRegisterItselfOnMonitors.
@Test
public void shouldRegisterItselfOnMonitors() {
// given
ClusterMembers clusterMembers = mock(ClusterMembers.class);
Cluster cluster = mock(Cluster.class);
SlaveFactory slaveFactory = mock(SlaveFactory.class);
// when
new HighAvailabilitySlaves(clusterMembers, cluster, slaveFactory, new HostnamePort(null, 0)).init();
// then
verify(cluster).addClusterListener(any(ClusterListener.class));
}
use of org.neo4j.kernel.ha.com.master.SlaveFactory in project neo4j by neo4j.
the class HighAvailabilitySlavesTest method shouldReturnAvailableAndAliveSlaves.
@Test
public void shouldReturnAvailableAndAliveSlaves() {
// given
Cluster cluster = mock(Cluster.class);
ClusterMembers clusterMembers = mock(ClusterMembers.class);
when(clusterMembers.getAliveMembers()).thenReturn(Iterables.option(new ClusterMember(INSTANCE_ID).availableAs(SLAVE, HA_URI, StoreId.DEFAULT)));
SlaveFactory slaveFactory = mock(SlaveFactory.class);
when(slaveFactory.newSlave(any(LifeSupport.class), any(ClusterMember.class), any(String.class), any(Integer.class))).thenReturn(mock(Slave.class));
HighAvailabilitySlaves slaves = new HighAvailabilitySlaves(clusterMembers, cluster, slaveFactory, new HostnamePort(null, 0));
slaves.init();
// when
Iterable<Slave> memberSlaves = slaves.getSlaves();
// then
assertThat(count(memberSlaves), equalTo(1L));
}
use of org.neo4j.kernel.ha.com.master.SlaveFactory in project neo4j by neo4j.
the class HighAvailabilitySlavesTest method shouldClearSlavesWhenNewMasterElected.
@Test
public void shouldClearSlavesWhenNewMasterElected() {
// given
Cluster cluster = mock(Cluster.class);
ClusterMembers clusterMembers = mock(ClusterMembers.class);
when(clusterMembers.getAliveMembers()).thenReturn(Iterables.option(new ClusterMember(INSTANCE_ID).availableAs(SLAVE, HA_URI, StoreId.DEFAULT)));
SlaveFactory slaveFactory = mock(SlaveFactory.class);
when(slaveFactory.newSlave(any(LifeSupport.class), any(ClusterMember.class), any(String.class), any(Integer.class))).thenReturn(mock(Slave.class), mock(Slave.class));
HighAvailabilitySlaves slaves = new HighAvailabilitySlaves(clusterMembers, cluster, slaveFactory, new HostnamePort(null, 0));
slaves.init();
ArgumentCaptor<ClusterListener> listener = ArgumentCaptor.forClass(ClusterListener.class);
verify(cluster).addClusterListener(listener.capture());
// when
Slave slave1 = slaves.getSlaves().iterator().next();
listener.getValue().elected(ClusterConfiguration.COORDINATOR, INSTANCE_ID, CLUSTER_URI);
Slave slave2 = slaves.getSlaves().iterator().next();
// then
assertThat(slave2, not(sameInstance(slave1)));
}
use of org.neo4j.kernel.ha.com.master.SlaveFactory in project neo4j by neo4j.
the class HighAvailabilitySlavesTest method shouldNotReturnUnavailableSlaves.
@Test
public void shouldNotReturnUnavailableSlaves() {
// given
Cluster cluster = mock(Cluster.class);
ClusterMembers clusterMembers = mock(ClusterMembers.class);
when(clusterMembers.getAliveMembers()).thenReturn(Iterables.option(new ClusterMember(INSTANCE_ID)));
SlaveFactory slaveFactory = mock(SlaveFactory.class);
HighAvailabilitySlaves slaves = new HighAvailabilitySlaves(clusterMembers, cluster, slaveFactory, new HostnamePort(null, 0));
slaves.init();
// when
Iterable<Slave> memberSlaves = slaves.getSlaves();
// then
assertThat(count(memberSlaves), equalTo(0L));
}
Aggregations