Search in sources :

Example 1 with SlaveFactory

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));
}
Also used : ClusterListener(org.neo4j.cluster.protocol.cluster.ClusterListener) HostnamePort(org.neo4j.helpers.HostnamePort) Cluster(org.neo4j.cluster.protocol.cluster.Cluster) SlaveFactory(org.neo4j.kernel.ha.com.master.SlaveFactory) DefaultSlaveFactory(org.neo4j.kernel.ha.com.master.DefaultSlaveFactory) Test(org.junit.Test)

Example 2 with SlaveFactory

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));
}
Also used : Slave(org.neo4j.kernel.ha.com.master.Slave) HostnamePort(org.neo4j.helpers.HostnamePort) Cluster(org.neo4j.cluster.protocol.cluster.Cluster) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) SlaveFactory(org.neo4j.kernel.ha.com.master.SlaveFactory) DefaultSlaveFactory(org.neo4j.kernel.ha.com.master.DefaultSlaveFactory) Test(org.junit.Test)

Example 3 with SlaveFactory

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)));
}
Also used : Slave(org.neo4j.kernel.ha.com.master.Slave) ClusterListener(org.neo4j.cluster.protocol.cluster.ClusterListener) HostnamePort(org.neo4j.helpers.HostnamePort) Cluster(org.neo4j.cluster.protocol.cluster.Cluster) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) SlaveFactory(org.neo4j.kernel.ha.com.master.SlaveFactory) DefaultSlaveFactory(org.neo4j.kernel.ha.com.master.DefaultSlaveFactory) Test(org.junit.Test)

Example 4 with SlaveFactory

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));
}
Also used : Slave(org.neo4j.kernel.ha.com.master.Slave) HostnamePort(org.neo4j.helpers.HostnamePort) Cluster(org.neo4j.cluster.protocol.cluster.Cluster) SlaveFactory(org.neo4j.kernel.ha.com.master.SlaveFactory) DefaultSlaveFactory(org.neo4j.kernel.ha.com.master.DefaultSlaveFactory) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 Cluster (org.neo4j.cluster.protocol.cluster.Cluster)4 HostnamePort (org.neo4j.helpers.HostnamePort)4 DefaultSlaveFactory (org.neo4j.kernel.ha.com.master.DefaultSlaveFactory)4 SlaveFactory (org.neo4j.kernel.ha.com.master.SlaveFactory)4 Slave (org.neo4j.kernel.ha.com.master.Slave)3 ClusterListener (org.neo4j.cluster.protocol.cluster.ClusterListener)2 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)2