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);
}
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))));
}
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))));
}
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);
}
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);
}
Aggregations