Search in sources :

Example 11 with Slave

use of org.neo4j.kernel.ha.com.master.Slave in project neo4j by neo4j.

the class TestMasterCommittingAtSlave method commitFailureAtFirstOneShouldMoveOnToNext.

@Test
public void commitFailureAtFirstOneShouldMoveOnToNext() throws Exception {
    TransactionPropagator propagator = newPropagator(3, 1, givenOrder(), true);
    propagator.committed(2, MasterServerId);
    Iterator<Slave> slaveIt = slaves.iterator();
    assertCalls((FakeSlave) slaveIt.next());
    assertCalls((FakeSlave) slaveIt.next(), 2);
    logProvider.assertNone(communicationLogMessage);
}
Also used : TransactionPropagator(org.neo4j.kernel.ha.transaction.TransactionPropagator) Slave(org.neo4j.kernel.ha.com.master.Slave) Test(org.junit.Test)

Example 12 with Slave

use of org.neo4j.kernel.ha.com.master.Slave 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 13 with Slave

use of org.neo4j.kernel.ha.com.master.Slave 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 14 with Slave

use of org.neo4j.kernel.ha.com.master.Slave 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)

Example 15 with Slave

use of org.neo4j.kernel.ha.com.master.Slave in project neo4j by neo4j.

the class CommitPusher method askSlaveToPullUpdates.

private void askSlaveToPullUpdates(PullUpdateFuture pullUpdateFuture) {
    Slave slave = pullUpdateFuture.getSlave();
    long lastTxId = pullUpdateFuture.getTxId();
    try (Response<Void> ignored = slave.pullUpdates(lastTxId)) {
    // Slave will come back to me(master) and pull updates
    }
}
Also used : Slave(org.neo4j.kernel.ha.com.master.Slave)

Aggregations

Slave (org.neo4j.kernel.ha.com.master.Slave)16 Test (org.junit.Test)13 TransactionPropagator (org.neo4j.kernel.ha.transaction.TransactionPropagator)6 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)3 SlavePriority (org.neo4j.kernel.ha.com.master.SlavePriority)3 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)3 ArrayList (java.util.ArrayList)2 Configuration (org.neo4j.kernel.ha.transaction.TransactionPropagator.Configuration)2 URI (java.net.URI)1 HashSet (java.util.HashSet)1 Callable (java.util.concurrent.Callable)1 ExecutorService (java.util.concurrent.ExecutorService)1 ClusterListener (org.neo4j.cluster.protocol.cluster.ClusterListener)1 TransactionObligationFulfiller (org.neo4j.com.storecopy.TransactionObligationFulfiller)1 UpdatePullerScheduler (org.neo4j.kernel.ha.UpdatePullerScheduler)1 MasterClient (org.neo4j.kernel.ha.com.slave.MasterClient)1 SlaveImpl (org.neo4j.kernel.ha.com.slave.SlaveImpl)1