use of org.apache.ignite.network.NetworkAddress in project ignite-3 by apache.
the class ItCliServiceTest method setup.
/**
* Executes before each test.
*/
@BeforeEach
public void setup(TestInfo testInfo, @WorkDirectory Path dataPath) throws Exception {
LOG.info(">>>>>>>>>>>>>>> Start test method: " + testInfo.getDisplayName());
List<PeerId> peers = TestUtils.generatePeers(3);
LinkedHashSet<PeerId> learners = new LinkedHashSet<>();
// 2 learners
for (int i = 0; i < 2; i++) {
learners.add(new PeerId(TestUtils.getLocalAddress(), TestUtils.INIT_PORT + LEARNER_PORT_STEP + i));
}
cluster = new TestCluster(groupId, dataPath.toString(), peers, learners, ELECTION_TIMEOUT_MILLIS, testInfo);
for (PeerId peer : peers) {
cluster.start(peer.getEndpoint());
}
for (PeerId peer : learners) {
cluster.startLearner(peer);
}
cluster.waitLeader();
cluster.ensureLeader(cluster.getLeader());
cliService = new CliServiceImpl();
conf = new Configuration(peers, learners);
CliOptions opts = new CliOptions();
clientExecutor = JRaftUtils.createClientExecutor(opts, "client");
opts.setClientExecutor(clientExecutor);
List<NetworkAddress> addressList = peers.stream().map(PeerId::getEndpoint).map(JRaftUtils::addressFromEndpoint).collect(toList());
ClusterService clientSvc = ClusterServiceTestUtils.clusterService(testInfo, TestUtils.INIT_PORT - 1, new StaticNodeFinder(addressList), new TestScaleCubeClusterServiceFactory());
clientSvc.start();
IgniteRpcClient rpcClient = new IgniteRpcClient(clientSvc) {
@Override
public void shutdown() {
super.shutdown();
clientSvc.stop();
}
};
opts.setRpcClient(rpcClient);
assertTrue(cliService.init(opts));
}
use of org.apache.ignite.network.NetworkAddress in project ignite-3 by apache.
the class ItInternalTableScanTest method setUp.
/**
* Prepare test environment.
* <ol>
* <li>Start network node.</li>
* <li>Start raft server.</li>
* <li>Prepare partitioned raft group.</li>
* <li>Prepare partitioned raft group service.</li>
* <li>Prepare internal table as a test object.</li>
* </ol>
*
* @throws Exception If any.
*/
@BeforeEach
public void setUp(TestInfo testInfo) throws Exception {
NetworkAddress nodeNetworkAddress = new NetworkAddress("localhost", 20_000);
network = ClusterServiceTestUtils.clusterService(testInfo, 20_000, new StaticNodeFinder(List.of(nodeNetworkAddress)), NETWORK_FACTORY);
network.start();
raftSrv = new RaftServerImpl(network, FACTORY);
raftSrv.start();
String grpName = "test_part_grp";
List<Peer> conf = List.of(new Peer(nodeNetworkAddress));
mockStorage = mock(PartitionStorage.class);
txManager = new TxManagerImpl(network, new HeapLockManager());
txManager.start();
UUID tblId = UUID.randomUUID();
raftSrv.startRaftGroup(grpName, new PartitionListener(tblId, new VersionedRowStore(mockStorage, txManager) {
@Override
protected Pair<BinaryRow, BinaryRow> versionedRow(@Nullable DataRow row, Timestamp timestamp) {
// Return as is.
return new Pair<>(new ByteBufferRow(row.valueBytes()), null);
}
}), conf);
executor = new ScheduledThreadPoolExecutor(20, new NamedThreadFactory(Loza.CLIENT_POOL_NAME));
RaftGroupService raftGrpSvc = RaftGroupServiceImpl.start(RAFT_GRP_ID, network, FACTORY, 10_000, conf, true, 200, executor).get(3, TimeUnit.SECONDS);
internalTbl = new InternalTableImpl(TEST_TABLE_NAME, tblId, Int2ObjectMaps.singleton(0, raftGrpSvc), 1, NetworkAddress::toString, txManager, mock(TableStorage.class));
}
use of org.apache.ignite.network.NetworkAddress in project ignite-3 by apache.
the class ItTablePersistenceTest method afterSnapshot.
/**
* {@inheritDoc}
*/
@Override
public void afterSnapshot(RaftGroupService service) throws Exception {
TxManager txManager = new TxManagerImpl(clientService(), new HeapLockManager());
managers.add(txManager);
txManager.start();
var table = new InternalTableImpl("table", UUID.randomUUID(), Int2ObjectMaps.singleton(0, service), 1, NetworkAddress::toString, txManager, mock(TableStorage.class));
table.upsert(SECOND_VALUE, null).get();
assertNotNull(table.get(SECOND_KEY, null).join());
txManager.stop();
}
use of org.apache.ignite.network.NetworkAddress in project ignite-3 by apache.
the class ItNodeRestartsTest method testRestarts.
/**
* Tests that restarting nodes get discovered in an established topology.
*/
@Test
public void testRestarts(TestInfo testInfo) {
final int initPort = 3344;
List<NetworkAddress> addresses = findLocalAddresses(initPort, initPort + 5);
var nodeFinder = new StaticNodeFinder(addresses);
services = addresses.stream().map(addr -> startNetwork(testInfo, addr, nodeFinder)).collect(// ensure mutability
Collectors.toCollection(ArrayList::new));
for (ClusterService service : services) {
assertTrue(waitForTopology(service, 5, 5_000), service.topologyService().localMember().toString() + ", topSize=" + service.topologyService().allMembers().size());
}
int idx0 = 0;
int idx1 = 2;
LOG.info("Shutdown {}", addresses.get(idx0));
services.get(idx0).stop();
LOG.info("Shutdown {}", addresses.get(idx1));
services.get(idx1).stop();
LOG.info("Starting {}", addresses.get(idx0));
ClusterService svc0 = startNetwork(testInfo, addresses.get(idx0), nodeFinder);
services.set(idx0, svc0);
LOG.info("Starting {}", addresses.get(idx1));
ClusterService svc2 = startNetwork(testInfo, addresses.get(idx1), nodeFinder);
services.set(idx1, svc2);
for (ClusterService service : services) {
assertTrue(waitForTopology(service, 5, 10_000), service.topologyService().localMember().toString() + ", topSize=" + service.topologyService().allMembers().size());
}
LOG.info("Reached stable state");
}
use of org.apache.ignite.network.NetworkAddress in project ignite-3 by apache.
the class ItScaleCubeNetworkMessagingTest method testSendMessageToSelf.
/**
* Sends a message from a node to itself and verifies that it gets delivered successfully.
*
* @throws Exception in case of errors.
*/
@Test
public void testSendMessageToSelf(TestInfo testInfo) throws Exception {
testCluster = new Cluster(1, testInfo);
testCluster.startAwait();
ClusterService member = testCluster.members.get(0);
ClusterNode self = member.topologyService().localMember();
class Data {
private final TestMessage message;
private final NetworkAddress sender;
private final Long correlationId;
private Data(TestMessage message, NetworkAddress sender, Long correlationId) {
this.message = message;
this.sender = sender;
this.correlationId = correlationId;
}
}
var dataFuture = new CompletableFuture<Data>();
member.messagingService().addMessageHandler(TestMessageTypes.class, (message, senderAddr, correlationId) -> dataFuture.complete(new Data((TestMessage) message, senderAddr, correlationId)));
var requestMessage = messageFactory.testMessage().msg("request").build();
member.messagingService().send(self, requestMessage);
Data actualData = dataFuture.get(3, TimeUnit.SECONDS);
assertThat(actualData.message.msg(), is(requestMessage.msg()));
assertThat(actualData.sender.consistentId(), is(self.name()));
assertNull(actualData.correlationId);
}
Aggregations