use of org.apache.ignite.network.ClusterService 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);
}
use of org.apache.ignite.network.ClusterService in project ignite-3 by apache.
the class ItScaleCubeNetworkMessagingTest method testShutdown0.
/**
* Tests shutdown.
*
* @param testInfo Test info.
* @param forceful Whether shutdown should be forceful.
* @throws Exception If failed.
*/
private void testShutdown0(TestInfo testInfo, boolean forceful) throws Exception {
testCluster = new Cluster(2, testInfo);
testCluster.startAwait();
ClusterService alice = testCluster.members.get(0);
ClusterService bob = testCluster.members.get(1);
String aliceName = alice.localConfiguration().getName();
var aliceShutdownLatch = new CountDownLatch(1);
bob.topologyService().addEventHandler(new TopologyEventHandler() {
/**
* {@inheritDoc}
*/
@Override
public void onAppeared(ClusterNode member) {
// No-op.
}
/**
* {@inheritDoc}
*/
@Override
public void onDisappeared(ClusterNode member) {
if (aliceName.equals(member.name())) {
aliceShutdownLatch.countDown();
}
}
});
if (forceful) {
stopForcefully(alice);
} else {
alice.stop();
}
boolean aliceShutdownReceived = aliceShutdownLatch.await(forceful ? 10 : 3, TimeUnit.SECONDS);
assertTrue(aliceShutdownReceived);
Collection<ClusterNode> networkMembers = bob.topologyService().allMembers();
assertEquals(1, networkMembers.size());
}
use of org.apache.ignite.network.ClusterService in project ignite-3 by apache.
the class ClusterServiceTestUtils method clusterService.
/**
* Creates a cluster service and required node configuration manager beneath it. Populates node configuration with specified port.
* Manages configuration manager lifecycle: on cluster service start starts node configuration manager, on cluster service stop - stops
* node configuration manager.
*
* @param testInfo Test info.
* @param port Local port.
* @param nodeFinder Node finder.
* @param clusterSvcFactory Cluster service factory.
*/
public static ClusterService clusterService(TestInfo testInfo, int port, NodeFinder nodeFinder, TestScaleCubeClusterServiceFactory clusterSvcFactory) {
var registry = new MessageSerializationRegistryImpl();
REGISTRY_INITIALIZERS.forEach(c -> {
try {
c.invoke(c.getDeclaringClass(), registry);
} catch (Throwable e) {
throw new RuntimeException("Failed to invoke registry initializer", e);
}
});
var ctx = new ClusterLocalConfiguration(testNodeName(testInfo, port), registry);
ConfigurationManager nodeConfigurationMgr = new ConfigurationManager(Collections.singleton(NetworkConfiguration.KEY), Map.of(), new TestConfigurationStorage(ConfigurationType.LOCAL), List.of(), List.of());
NetworkConfiguration configuration = nodeConfigurationMgr.configurationRegistry().getConfiguration(NetworkConfiguration.KEY);
var bootstrapFactory = new NettyBootstrapFactory(configuration, ctx.getName());
var clusterSvc = clusterSvcFactory.createClusterService(ctx, configuration, bootstrapFactory);
assert nodeFinder instanceof StaticNodeFinder : "Only StaticNodeFinder is supported at the moment";
return new ClusterService() {
@Override
public TopologyService topologyService() {
return clusterSvc.topologyService();
}
@Override
public MessagingService messagingService() {
return clusterSvc.messagingService();
}
@Override
public ClusterLocalConfiguration localConfiguration() {
return clusterSvc.localConfiguration();
}
@Override
public boolean isStopped() {
return clusterSvc.isStopped();
}
@Override
public void start() {
nodeConfigurationMgr.start();
NetworkConfiguration configuration = nodeConfigurationMgr.configurationRegistry().getConfiguration(NetworkConfiguration.KEY);
configuration.change(netCfg -> netCfg.changePort(port).changeNodeFinder(c -> c.changeType(NodeFinderType.STATIC.toString()).changeNetClusterNodes(nodeFinder.findNodes().stream().map(NetworkAddress::toString).toArray(String[]::new)))).join();
bootstrapFactory.start();
clusterSvc.start();
}
@Override
public void stop() {
try {
clusterSvc.stop();
bootstrapFactory.stop();
nodeConfigurationMgr.stop();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
}
use of org.apache.ignite.network.ClusterService in project ignite-3 by apache.
the class RecordBinaryViewOperationsTest method createTableImpl.
@NotNull
private TableImpl createTableImpl(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));
}
use of org.apache.ignite.network.ClusterService in project ignite-3 by apache.
the class RecordViewOperationsTest method recordView.
/**
* Creates RecordView.
*/
private RecordViewImpl<TestObjectWithAllTypes> recordView() {
ClusterService clusterService = Mockito.mock(ClusterService.class, RETURNS_DEEP_STUBS);
Mockito.when(clusterService.topologyService().localMember().address()).thenReturn(DummyInternalTableImpl.ADDR);
TxManager txManager = new TxManagerImpl(clusterService, new HeapLockManager());
MessagingService messagingService = MessagingServiceTestUtils.mockMessagingService(txManager);
Mockito.when(clusterService.messagingService()).thenReturn(messagingService);
DummyInternalTableImpl table = new DummyInternalTableImpl(new VersionedRowStore(new ConcurrentHashMapPartitionStorage(), txManager), txManager);
Mapper<TestObjectWithAllTypes> recMapper = Mapper.of(TestObjectWithAllTypes.class);
Column[] valCols = { new Column("primitiveByteCol".toUpperCase(), INT8, false), new Column("primitiveShortCol".toUpperCase(), INT16, false), new Column("primitiveIntCol".toUpperCase(), INT32, false), new Column("primitiveFloatCol".toUpperCase(), FLOAT, false), new Column("primitiveDoubleCol".toUpperCase(), DOUBLE, false), new Column("byteCol".toUpperCase(), INT8, true), new Column("shortCol".toUpperCase(), INT16, true), new Column("intCol".toUpperCase(), INT32, true), new Column("longCol".toUpperCase(), INT64, true), new Column("nullLongCol".toUpperCase(), INT64, true), new Column("floatCol".toUpperCase(), FLOAT, true), new Column("doubleCol".toUpperCase(), DOUBLE, true), new Column("dateCol".toUpperCase(), DATE, true), new Column("timeCol".toUpperCase(), time(), true), new Column("dateTimeCol".toUpperCase(), datetime(), true), new Column("timestampCol".toUpperCase(), timestamp(), true), new Column("uuidCol".toUpperCase(), NativeTypes.UUID, true), new Column("bitmaskCol".toUpperCase(), NativeTypes.bitmaskOf(42), true), new Column("stringCol".toUpperCase(), STRING, true), new Column("nullBytesCol".toUpperCase(), BYTES, true), new Column("bytesCol".toUpperCase(), BYTES, true), new Column("numberCol".toUpperCase(), NativeTypes.numberOf(12), true), new Column("decimalCol".toUpperCase(), NativeTypes.decimalOf(19, 3), true) };
SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("primitiveLongCol".toUpperCase(), NativeTypes.INT64, false) }, valCols);
// Validate all types are tested.
Set<NativeTypeSpec> testedTypes = Arrays.stream(valCols).map(c -> c.type().spec()).collect(Collectors.toSet());
Set<NativeTypeSpec> missedTypes = Arrays.stream(NativeTypeSpec.values()).filter(t -> !testedTypes.contains(t)).collect(Collectors.toSet());
assertEquals(Collections.emptySet(), missedTypes);
return new RecordViewImpl<>(table, new DummySchemaManagerImpl(schema), recMapper);
}
Aggregations