Search in sources :

Example 1 with SlavePriority

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

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

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

the class TestMasterCommittingAtSlave method testFixedPriorityStrategy.

@Test
public void testFixedPriorityStrategy() {
    int[] serverIds = new int[] { 55, 101, 66 };
    SlavePriority fixed = SlavePriorities.fixedDescending();
    ArrayList<Slave> slaves = new ArrayList<>(3);
    slaves.add(new FakeSlave(false, serverIds[0]));
    slaves.add(new FakeSlave(false, serverIds[1]));
    slaves.add(new FakeSlave(false, serverIds[2]));
    Iterator<Slave> sortedSlaves = fixed.prioritize(slaves).iterator();
    assertEquals(serverIds[1], sortedSlaves.next().getServerId());
    assertEquals(serverIds[2], sortedSlaves.next().getServerId());
    assertEquals(serverIds[0], sortedSlaves.next().getServerId());
    assertTrue(!sortedSlaves.hasNext());
}
Also used : Slave(org.neo4j.kernel.ha.com.master.Slave) ArrayList(java.util.ArrayList) SlavePriority(org.neo4j.kernel.ha.com.master.SlavePriority) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 Slave (org.neo4j.kernel.ha.com.master.Slave)3 SlavePriority (org.neo4j.kernel.ha.com.master.SlavePriority)3 Configuration (org.neo4j.kernel.ha.transaction.TransactionPropagator.Configuration)2 ArrayList (java.util.ArrayList)1