Search in sources :

Example 1 with Slave

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

the class HighAvailabilitySlavesTest method shouldSupportConcurrentConsumptionOfSlaves.

@Test
public void shouldSupportConcurrentConsumptionOfSlaves() throws Exception {
    // Given
    LogEntryReader<ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader<>();
    HighAvailabilitySlaves haSlaves = new HighAvailabilitySlaves(clusterMembersOfSize(1000), mock(Cluster.class), new DefaultSlaveFactory(NullLogProvider.getInstance(), new Monitors(), 42, Suppliers.singleton(logEntryReader)), new HostnamePort(null, 0));
    // When
    ExecutorService executor = Executors.newFixedThreadPool(5);
    for (int i = 0; i < 5; i++) {
        executor.submit(slavesConsumingRunnable(haSlaves));
    }
    executor.shutdown();
    executor.awaitTermination(30, SECONDS);
    // Then
    int slavesCount = 0;
    LifeSupport life = ReflectionUtil.getPrivateField(haSlaves, "life", LifeSupport.class);
    for (Lifecycle lifecycle : life.getLifecycleInstances()) {
        if (lifecycle instanceof Slave) {
            slavesCount++;
        }
    }
    // One instance is master
    assertEquals("Unexpected number of slaves", 1000 - 1, slavesCount);
}
Also used : HostnamePort(org.neo4j.helpers.HostnamePort) Lifecycle(org.neo4j.kernel.lifecycle.Lifecycle) Cluster(org.neo4j.cluster.protocol.cluster.Cluster) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel) Slave(org.neo4j.kernel.ha.com.master.Slave) Monitors(org.neo4j.kernel.monitoring.Monitors) ExecutorService(java.util.concurrent.ExecutorService) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) DefaultSlaveFactory(org.neo4j.kernel.ha.com.master.DefaultSlaveFactory) Test(org.junit.Test)

Example 2 with Slave

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

the class TransactionPropagatorTest method shouldPrioritizeDescendingIfAsked.

@Test
public void shouldPrioritizeDescendingIfAsked() throws Exception {
    // GIVEN
    Configuration propagator = TransactionPropagator.from(Config.embeddedDefaults(stringMap(tx_push_strategy.name(), fixed_descending.name())));
    SlavePriority strategy = propagator.getReplicationStrategy();
    // WHEN
    Iterable<Slave> prioritize = strategy.prioritize(asList(slave(1), slave(0), slave(2)));
    // THEN
    assertThat(Iterables.asList(prioritize), equalTo(asList(slave(2), slave(1), slave(0))));
}
Also used : Slave(org.neo4j.kernel.ha.com.master.Slave) Configuration(org.neo4j.kernel.ha.transaction.TransactionPropagator.Configuration) SlavePriority(org.neo4j.kernel.ha.com.master.SlavePriority) Test(org.junit.Test)

Example 3 with Slave

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

the class TransactionPropagatorTest method shouldPrioritizeAscendingIfAsked.

@Test
public void shouldPrioritizeAscendingIfAsked() throws Exception {
    // GIVEN
    Configuration propagator = TransactionPropagator.from(Config.embeddedDefaults(stringMap(tx_push_strategy.name(), fixed_ascending.name())));
    SlavePriority strategy = propagator.getReplicationStrategy();
    // WHEN
    Iterable<Slave> prioritize = strategy.prioritize(asList(slave(1), slave(0), slave(2)));
    // THEN
    assertThat(Iterables.asList(prioritize), equalTo(asList(slave(0), slave(1), slave(2))));
}
Also used : Slave(org.neo4j.kernel.ha.com.master.Slave) Configuration(org.neo4j.kernel.ha.transaction.TransactionPropagator.Configuration) SlavePriority(org.neo4j.kernel.ha.com.master.SlavePriority) Test(org.junit.Test)

Example 4 with Slave

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

the class TestMasterCommittingAtSlave method roundRobinSingleSlave.

@Test
public void roundRobinSingleSlave() throws Exception {
    TransactionPropagator propagator = newPropagator(3, 1, roundRobin());
    for (long tx = 2; tx <= 6; tx++) {
        propagator.committed(tx, MasterServerId);
    }
    Iterator<Slave> slaveIt = slaves.iterator();
    assertCalls((FakeSlave) slaveIt.next(), 2, 5);
    assertCalls((FakeSlave) slaveIt.next(), 3, 6);
    assertCalls((FakeSlave) slaveIt.next(), 4);
    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 5 with Slave

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

the class TestMasterCommittingAtSlave method commitSuccessfullyOnSomeOfThreeSlaves.

@Test
public void commitSuccessfullyOnSomeOfThreeSlaves() throws Exception {
    TransactionPropagator propagator = newPropagator(5, 3, givenOrder(), false, true, true);
    propagator.committed(2, MasterServerId);
    Iterator<Slave> slaveIt = slaves.iterator();
    assertCalls((FakeSlave) slaveIt.next(), 2);
    slaveIt.next();
    slaveIt.next();
    assertCalls((FakeSlave) slaveIt.next(), 2);
    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)

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