use of org.apache.ignite.network.ClusterService in project ignite-3 by apache.
the class ItSimpleCounterServerTest method before.
/**
* Before each.
*/
@BeforeEach
void before() throws Exception {
LOG.info(">>>> Starting test {}", testInfo.getTestMethod().orElseThrow().getName());
var addr = new NetworkAddress("localhost", PORT);
ClusterService service = clusterService(PORT, List.of(addr), true);
server = new JraftServerImpl(service, dataPath) {
@Override
public synchronized void stop() {
super.stop();
service.stop();
}
};
server.start();
ClusterNode serverNode = server.clusterService().topologyService().localMember();
assertTrue(server.startRaftGroup(COUNTER_GROUP_ID_0, new CounterListener(), List.of(new Peer(serverNode.address()))));
assertTrue(server.startRaftGroup(COUNTER_GROUP_ID_1, new CounterListener(), List.of(new Peer(serverNode.address()))));
ClusterService clientNode1 = clusterService(PORT + 1, List.of(addr), true);
executor = new ScheduledThreadPoolExecutor(20, new NamedThreadFactory(Loza.CLIENT_POOL_NAME));
client1 = RaftGroupServiceImpl.start(COUNTER_GROUP_ID_0, clientNode1, FACTORY, 1000, List.of(new Peer(serverNode.address())), false, 200, executor).get(3, TimeUnit.SECONDS);
ClusterService clientNode2 = clusterService(PORT + 2, List.of(addr), true);
client2 = RaftGroupServiceImpl.start(COUNTER_GROUP_ID_1, clientNode2, FACTORY, 1000, List.of(new Peer(serverNode.address())), false, 200, executor).get(3, TimeUnit.SECONDS);
assertTrue(waitForTopology(service, 3, 1000));
assertTrue(waitForTopology(clientNode1, 3, 1000));
assertTrue(waitForTopology(clientNode2, 3, 1000));
}
use of org.apache.ignite.network.ClusterService in project ignite-3 by apache.
the class ItAbstractListenerSnapshotTest method afterTest.
/**
* Shutdown raft server, executor for raft group services and stop all cluster nodes.
*
* @throws Exception If failed to shutdown raft server,
*/
@AfterEach
public void afterTest() throws Exception {
for (JraftServerImpl server : servers) {
server.stopRaftGroup(raftGroupId());
}
for (RaftGroupService client : clients) {
client.shutdown();
}
IgniteUtils.shutdownAndAwaitTermination(executor, 10, TimeUnit.SECONDS);
for (JraftServerImpl server : servers) {
server.beforeNodeStop();
server.stop();
}
for (ClusterService service : cluster) {
service.stop();
}
}
use of org.apache.ignite.network.ClusterService in project ignite-3 by apache.
the class ItAbstractListenerSnapshotTest method startServer.
/**
* Starts a raft server.
*
* @param testInfo Test info.
* @param idx Server index (affects port of the server).
* @return Server.
*/
private JraftServerImpl startServer(TestInfo testInfo, int idx) {
var addr = new NetworkAddress(getLocalAddress(), PORT);
ClusterService service = clusterService(testInfo, PORT + idx, addr);
Path jraft = workDir.resolve("jraft" + idx);
JraftServerImpl server = new JraftServerImpl(service, jraft) {
@Override
public void stop() {
super.stop();
service.stop();
}
};
server.start();
Path listenerPersistencePath = workDir.resolve("db" + idx);
servers.add(server);
server.startRaftGroup(raftGroupId(), createListener(service, listenerPersistencePath), INITIAL_CONF);
return server;
}
use of org.apache.ignite.network.ClusterService in project ignite-3 by apache.
the class ScaleCubeClusterServiceFactory method createClusterService.
/**
* Creates a new {@link ClusterService} using the provided context. The created network will not be in the "started" state.
*
* @param context Cluster context.
* @param networkConfiguration Network configuration.
* @param nettyBootstrapFactory Bootstrap factory.
* @return New cluster service.
*/
public ClusterService createClusterService(ClusterLocalConfiguration context, NetworkConfiguration networkConfiguration, NettyBootstrapFactory nettyBootstrapFactory) {
var messageFactory = new NetworkMessagesFactory();
var topologyService = new ScaleCubeTopologyService();
UserObjectSerializationContext userObjectSerialization = createUserObjectSerializationContext();
var messagingService = new DefaultMessagingService(messageFactory, topologyService, userObjectSerialization);
return new AbstractClusterService(context, topologyService, messagingService) {
private volatile ClusterImpl cluster;
private volatile ConnectionManager connectionMgr;
private volatile CompletableFuture<Void> shutdownFuture;
/**
* {@inheritDoc}
*/
@Override
public void start() {
String consistentId = context.getName();
var serializationService = new SerializationService(context.getSerializationRegistry(), userObjectSerialization);
UUID launchId = UUID.randomUUID();
NetworkView configView = networkConfiguration.value();
connectionMgr = new ConnectionManager(configView, serializationService, consistentId, () -> new RecoveryServerHandshakeManager(launchId, consistentId, messageFactory), () -> new RecoveryClientHandshakeManager(launchId, consistentId, messageFactory), nettyBootstrapFactory);
connectionMgr.start();
var transport = new ScaleCubeDirectMarshallerTransport(connectionMgr.getLocalAddress(), messagingService, topologyService, messageFactory);
NodeFinder finder = NodeFinderFactory.createNodeFinder(configView.nodeFinder());
cluster = new ClusterImpl(clusterConfig(configView.membership())).handler(cl -> new ClusterMessageHandler() {
/**
* {@inheritDoc}
*/
@Override
public void onMembershipEvent(MembershipEvent event) {
topologyService.onMembershipEvent(event);
}
}).config(opts -> opts.memberAlias(consistentId)).transport(opts -> opts.transportFactory(transportConfig -> transport)).membership(opts -> opts.seedMembers(parseAddresses(finder.findNodes())));
shutdownFuture = cluster.onShutdown().toFuture();
// resolve cyclic dependencies
topologyService.setCluster(cluster);
messagingService.setConnectionManager(connectionMgr);
cluster.startAwait();
// emit an artificial event as if the local member has joined the topology (ScaleCube doesn't do that)
var localMembershipEvent = MembershipEvent.createAdded(cluster.member(), null, System.currentTimeMillis());
topologyService.onMembershipEvent(localMembershipEvent);
}
/**
* {@inheritDoc}
*/
@Override
public void stop() {
// local member will be null, if cluster has not been started
if (cluster.member() == null) {
return;
}
cluster.shutdown();
try {
shutdownFuture.get(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IgniteInternalException("Interrupted while waiting for the ClusterService to stop", e);
} catch (TimeoutException e) {
throw new IgniteInternalException("Timeout while waiting for the ClusterService to stop", e);
} catch (ExecutionException e) {
throw new IgniteInternalException("Unable to stop the ClusterService", e.getCause());
}
connectionMgr.stop();
// Messaging service checks connection manager's status before sending a message, so connection manager should be
// stopped before messaging service
messagingService.stop();
}
/**
* {@inheritDoc}
*/
@Override
public void beforeNodeStop() {
stop();
}
/**
* {@inheritDoc}
*/
@Override
public boolean isStopped() {
return shutdownFuture.isDone();
}
};
}
use of org.apache.ignite.network.ClusterService in project ignite-3 by apache.
the class KeyValueViewOperationsSimpleSchemaTest method createTable.
@NotNull
private TableImpl createTable(SchemaDescriptor schema) {
ClusterService clusterService = Mockito.mock(ClusterService.class, RETURNS_DEEP_STUBS);
Mockito.when(clusterService.topologyService().localMember().address()).thenReturn(DummyInternalTableImpl.ADDR);
LockManager lockManager = new HeapLockManager();
TxManager txManager = new TxManagerImpl(clusterService, lockManager);
MessagingService messagingService = MessagingServiceTestUtils.mockMessagingService(txManager);
Mockito.when(clusterService.messagingService()).thenReturn(messagingService);
DummyInternalTableImpl table = new DummyInternalTableImpl(new VersionedRowStore(new ConcurrentHashMapPartitionStorage(), txManager), txManager);
return new TableImpl(table, new DummySchemaManagerImpl(schema));
}
Aggregations