Search in sources :

Example 36 with MemberId

use of org.neo4j.causalclustering.identity.MemberId in project neo4j by neo4j.

the class ConnectionInfoIT method hzTest.

@Test
public void hzTest() throws Throwable {
    // given
    testSocket = bindPort("0.0.0.0", 4243);
    //when
    AssertableLogProvider logProvider = new AssertableLogProvider();
    AssertableLogProvider userLogProvider = new AssertableLogProvider();
    HazelcastDiscoveryServiceFactory hzFactory = new HazelcastDiscoveryServiceFactory();
    Config config = embeddedDefaults(stringMap(discovery_listen_address.name(), ":" + testSocket.getLocalPort(), CausalClusteringSettings.initial_discovery_members.name(), "localhost:" + testSocket.getLocalPort(), new BoltConnector("bolt").enabled.name(), "true", new HttpConnector("http").enabled.name(), "true"));
    Neo4jJobScheduler jobScheduler = new Neo4jJobScheduler();
    jobScheduler.init();
    CoreTopologyService coreTopologyService = hzFactory.coreTopologyService(config, new MemberId(UUID.randomUUID()), jobScheduler, logProvider, userLogProvider);
    try {
        coreTopologyService.init();
        coreTopologyService.start();
    }//then
     catch (Throwable throwable) {
    //expected
    }
    logProvider.assertContainsMessageContaining("Hazelcast was unable to start with setting");
    userLogProvider.assertContainsMessageContaining("Hazelcast was unable to start with setting");
}
Also used : Neo4jJobScheduler(org.neo4j.kernel.impl.util.Neo4jJobScheduler) MemberId(org.neo4j.causalclustering.identity.MemberId) HttpConnector(org.neo4j.kernel.configuration.HttpConnector) HazelcastDiscoveryServiceFactory(org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory) CoreTopologyService(org.neo4j.causalclustering.discovery.CoreTopologyService) BoltConnector(org.neo4j.kernel.configuration.BoltConnector) Config(org.neo4j.kernel.configuration.Config) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 37 with MemberId

use of org.neo4j.causalclustering.identity.MemberId in project neo4j by neo4j.

the class SegmentedRaftLogPartialEntryRecoveryTest method incompleteEntriesAtTheEndShouldNotCauseFailures.

@Test
public void incompleteEntriesAtTheEndShouldNotCauseFailures() throws Throwable {
    // Given
    // we use a RaftLog to create a raft log file and then we will start chopping bits off from the end
    SegmentedRaftLog raftLog = createRaftLog(100_000);
    raftLog.start();
    // Add a bunch of entries, preferably one of each available kind.
    raftLog.append(new RaftLogEntry(4, new NewLeaderBarrier()));
    raftLog.append(new RaftLogEntry(4, new ReplicatedIdAllocationRequest(new MemberId(UUID.randomUUID()), IdType.RELATIONSHIP, 1, 1024)));
    raftLog.append(new RaftLogEntry(4, new ReplicatedIdAllocationRequest(new MemberId(UUID.randomUUID()), IdType.RELATIONSHIP, 1025, 1024)));
    raftLog.append(new RaftLogEntry(4, new ReplicatedLockTokenRequest(new MemberId(UUID.randomUUID()), 1)));
    raftLog.append(new RaftLogEntry(4, new NewLeaderBarrier()));
    raftLog.append(new RaftLogEntry(5, new ReplicatedTokenRequest(TokenType.LABEL, "labelToken", new byte[] { 1, 2, 3 })));
    raftLog.append(new RaftLogEntry(5, new ReplicatedTransaction(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 })));
    raftLog.stop();
    // We use a temporary RecoveryProtocol to get the file to chop
    RecoveryProtocol recovery = createRecoveryProtocol();
    State recoveryState = recovery.run();
    String logFilename = recoveryState.segments.last().getFilename();
    File logFile = new File(logDirectory, logFilename);
    // When
    // We remove any number of bytes from the end (up to but not including the header) and try to recover
    // Then
    // No exceptions should be thrown
    truncateAndRecover(logFile, SegmentHeader.SIZE);
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) ReplicatedLockTokenRequest(org.neo4j.causalclustering.core.state.machines.locks.ReplicatedLockTokenRequest) ReplicatedTokenRequest(org.neo4j.causalclustering.core.state.machines.token.ReplicatedTokenRequest) ReplicatedIdAllocationRequest(org.neo4j.causalclustering.core.state.machines.id.ReplicatedIdAllocationRequest) ReplicatedTransaction(org.neo4j.causalclustering.core.state.machines.tx.ReplicatedTransaction) NewLeaderBarrier(org.neo4j.causalclustering.core.consensus.NewLeaderBarrier) File(java.io.File) RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry) Test(org.junit.Test)

Example 38 with MemberId

use of org.neo4j.causalclustering.identity.MemberId in project neo4j by neo4j.

the class MemberIdMarshalTest method shouldThrowExceptionForHalfWrittenInstance.

@Test
public void shouldThrowExceptionForHalfWrittenInstance() throws Exception {
    // given
    // a CoreMember and a ByteBuffer to write it to
    MemberId.Marshal marshal = new MemberId.Marshal();
    final MemberId aRealMember = new MemberId(UUID.randomUUID());
    ByteBuf buffer = Unpooled.buffer(1000);
    // and the CoreMember is serialized but for 5 bytes at the end
    marshal.marshal(aRealMember, new NetworkFlushableChannelNetty4(buffer));
    ByteBuf bufferWithMissingBytes = buffer.copy(0, buffer.writerIndex() - 5);
    // when
    try {
        marshal.unmarshal(new NetworkReadableClosableChannelNetty4(bufferWithMissingBytes));
        fail("Should have thrown exception");
    } catch (EndOfStreamException e) {
    // expected
    }
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) EndOfStreamException(org.neo4j.causalclustering.messaging.EndOfStreamException) NetworkFlushableChannelNetty4(org.neo4j.causalclustering.messaging.NetworkFlushableChannelNetty4) ByteBuf(io.netty.buffer.ByteBuf) NetworkReadableClosableChannelNetty4(org.neo4j.causalclustering.messaging.NetworkReadableClosableChannelNetty4) Test(org.junit.Test)

Example 39 with MemberId

use of org.neo4j.causalclustering.identity.MemberId in project neo4j by neo4j.

the class MemberIdMarshalTest method shouldSerializeAndDeserialize.

@Test
public void shouldSerializeAndDeserialize() throws Exception {
    // given
    MemberId.Marshal marshal = new MemberId.Marshal();
    final MemberId member = new MemberId(UUID.randomUUID());
    // when
    ByteBuf buffer = Unpooled.buffer(1_000);
    marshal.marshal(member, new NetworkFlushableChannelNetty4(buffer));
    final MemberId recovered = marshal.unmarshal(new NetworkReadableClosableChannelNetty4(buffer));
    // then
    assertEquals(member, recovered);
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) NetworkFlushableChannelNetty4(org.neo4j.causalclustering.messaging.NetworkFlushableChannelNetty4) ByteBuf(io.netty.buffer.ByteBuf) NetworkReadableClosableChannelNetty4(org.neo4j.causalclustering.messaging.NetworkReadableClosableChannelNetty4) Test(org.junit.Test)

Example 40 with MemberId

use of org.neo4j.causalclustering.identity.MemberId in project neo4j by neo4j.

the class RaftGroupMembershipTest method shouldNotFormGroupWithoutAnyBootstrapping.

@Test
public void shouldNotFormGroupWithoutAnyBootstrapping() throws Exception {
    // given
    DirectNetworking net = new DirectNetworking();
    final MemberId[] ids = { member(0), member(1), member(2) };
    RaftTestFixture fixture = new RaftTestFixture(net, 3, ids);
    fixture.members().setTargetMembershipSet(new RaftTestGroup(ids).getMembers());
    fixture.members().invokeTimeout(ELECTION);
    // when
    net.processMessages();
    // then
    assertThat(fixture.members(), hasCurrentMembers(new RaftTestGroup(new int[0])));
    assertEquals(0, fixture.members().withRole(LEADER).size());
    assertEquals(3, fixture.members().withRole(FOLLOWER).size());
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) RaftTestFixture(org.neo4j.causalclustering.core.consensus.RaftTestFixture) DirectNetworking(org.neo4j.causalclustering.core.consensus.DirectNetworking) Test(org.junit.Test)

Aggregations

MemberId (org.neo4j.causalclustering.identity.MemberId)114 Test (org.junit.Test)83 HashMap (java.util.HashMap)26 CoreTopology (org.neo4j.causalclustering.discovery.CoreTopology)16 CoreServerInfo (org.neo4j.causalclustering.discovery.CoreServerInfo)15 LeaderLocator (org.neo4j.causalclustering.core.consensus.LeaderLocator)13 ReadReplicaTopology (org.neo4j.causalclustering.discovery.ReadReplicaTopology)12 DirectNetworking (org.neo4j.causalclustering.core.consensus.DirectNetworking)10 RaftTestFixture (org.neo4j.causalclustering.core.consensus.RaftTestFixture)10 CoreTopologyService (org.neo4j.causalclustering.discovery.CoreTopologyService)10 Log (org.neo4j.logging.Log)10 ClusterId (org.neo4j.causalclustering.identity.ClusterId)9 ArrayList (java.util.ArrayList)8 UUID (java.util.UUID)8 RaftMessages (org.neo4j.causalclustering.core.consensus.RaftMessages)8 TopologyService (org.neo4j.causalclustering.discovery.TopologyService)7 ByteBuf (io.netty.buffer.ByteBuf)6 File (java.io.File)6 RaftLogEntry (org.neo4j.causalclustering.core.consensus.log.RaftLogEntry)6 HashSet (java.util.HashSet)5