Search in sources :

Example 26 with NetworkAddress

use of org.apache.ignite.network.NetworkAddress in project ignite-3 by apache.

the class TxManagerTest method testEnlist.

@Test
public void testEnlist() throws TransactionException {
    NetworkAddress addr = clusterService.topologyService().localMember().address();
    assertEquals(ADDR, addr);
    InternalTransaction tx = txManager.begin();
    RaftGroupService svc = Mockito.mock(RaftGroupService.class);
    tx.enlist(svc);
    assertEquals(1, tx.enlisted().size());
    assertTrue(tx.enlisted().contains(svc));
}
Also used : NetworkAddress(org.apache.ignite.network.NetworkAddress) RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) Test(org.junit.jupiter.api.Test) IgniteAbstractTest(org.apache.ignite.internal.testframework.IgniteAbstractTest)

Example 27 with NetworkAddress

use of org.apache.ignite.network.NetworkAddress in project ignite-3 by apache.

the class ItMetaStorageServiceTest method beforeTest.

/**
 * Run {@code NODES} cluster nodes.
 */
@BeforeEach
public void beforeTest(TestInfo testInfo) throws Exception {
    List<NetworkAddress> localAddresses = findLocalAddresses(NODE_PORT_BASE, NODE_PORT_BASE + NODES);
    var nodeFinder = new StaticNodeFinder(localAddresses);
    localAddresses.stream().map(addr -> ClusterServiceTestUtils.clusterService(testInfo, addr.port(), nodeFinder, NETWORK_FACTORY)).forEach(clusterService -> {
        clusterService.start();
        cluster.add(clusterService);
    });
    for (ClusterService node : cluster) {
        assertTrue(waitForTopology(node, NODES, 1000));
    }
    LOG.info("Cluster started.");
    executor = new ScheduledThreadPoolExecutor(20, new NamedThreadFactory(Loza.CLIENT_POOL_NAME));
    metaStorageSvc = prepareMetaStorage();
}
Also used : CompoundCondition.and(org.apache.ignite.internal.metastorage.client.CompoundCondition.and) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) StatementResult(org.apache.ignite.internal.metastorage.server.StatementResult) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) CompoundCondition.or(org.apache.ignite.internal.metastorage.client.CompoundCondition.or) ValueCondition(org.apache.ignite.internal.metastorage.server.ValueCondition) Disabled(org.junit.jupiter.api.Disabled) IgniteLogger(org.apache.ignite.lang.IgniteLogger) RaftMessagesFactory(org.apache.ignite.raft.jraft.RaftMessagesFactory) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) Map(java.util.Map) Path(java.nio.file.Path) Operations.ops(org.apache.ignite.internal.metastorage.client.Operations.ops) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) KeyValueStorage(org.apache.ignite.internal.metastorage.server.KeyValueStorage) EntryEvent(org.apache.ignite.internal.metastorage.server.EntryEvent) Collection(java.util.Collection) Set(java.util.Set) Cursor(org.apache.ignite.internal.util.Cursor) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Mockito.doNothing(org.mockito.Mockito.doNothing) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) NavigableMap(java.util.NavigableMap) Collectors(java.util.stream.Collectors) RevisionCondition(org.apache.ignite.internal.metastorage.server.RevisionCondition) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) TestInfo(org.junit.jupiter.api.TestInfo) RaftServer(org.apache.ignite.internal.raft.server.RaftServer) Conditions.value(org.apache.ignite.internal.metastorage.client.Conditions.value) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) StaticNodeFinder(org.apache.ignite.network.StaticNodeFinder) MetaStorageListener(org.apache.ignite.internal.metastorage.server.raft.MetaStorageListener) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) NotNull(org.jetbrains.annotations.NotNull) AbstractSimpleCondition(org.apache.ignite.internal.metastorage.server.AbstractSimpleCondition) RaftGroupServiceImpl(org.apache.ignite.raft.jraft.rpc.impl.RaftGroupServiceImpl) ClusterServiceTestUtils.findLocalAddresses(org.apache.ignite.utils.ClusterServiceTestUtils.findLocalAddresses) Mockito.mock(org.mockito.Mockito.mock) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Operations.remove(org.apache.ignite.internal.metastorage.client.Operations.remove) ClusterServiceTestUtils(org.apache.ignite.utils.ClusterServiceTestUtils) Mock(org.mockito.Mock) Loza(org.apache.ignite.internal.raft.Loza) ServerConditionMatcher.cond(org.apache.ignite.internal.metastorage.client.ItMetaStorageServiceTest.ServerConditionMatcher.cond) ArrayList(java.util.ArrayList) AndCondition(org.apache.ignite.internal.metastorage.server.AndCondition) RaftServerImpl(org.apache.ignite.internal.raft.server.impl.RaftServerImpl) If.iif(org.apache.ignite.internal.metastorage.client.If.iif) TestScaleCubeClusterServiceFactory(org.apache.ignite.network.scalecube.TestScaleCubeClusterServiceFactory) ArgumentCaptor(org.mockito.ArgumentCaptor) TestUtils.waitForTopology(org.apache.ignite.raft.jraft.test.TestUtils.waitForTopology) Type(org.apache.ignite.internal.metastorage.server.ValueCondition.Type) IgniteUtils(org.apache.ignite.internal.util.IgniteUtils) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Conditions.revision(org.apache.ignite.internal.metastorage.client.Conditions.revision) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) NoSuchElementException(java.util.NoSuchElementException) Description(org.hamcrest.Description) Iterator(java.util.Iterator) ByteArray(org.apache.ignite.lang.ByteArray) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) OrCondition(org.apache.ignite.internal.metastorage.server.OrCondition) Mockito.verify(org.mockito.Mockito.verify) WorkDirectory(org.apache.ignite.internal.testframework.WorkDirectory) NetworkAddress(org.apache.ignite.network.NetworkAddress) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) TimeUnit(java.util.concurrent.TimeUnit) Collectors.toList(java.util.stream.Collectors.toList) Peer(org.apache.ignite.raft.client.Peer) AfterEach(org.junit.jupiter.api.AfterEach) Operations.put(org.apache.ignite.internal.metastorage.client.Operations.put) TreeMap(java.util.TreeMap) AbstractCompoundCondition(org.apache.ignite.internal.metastorage.server.AbstractCompoundCondition) OperationType(org.apache.ignite.internal.metastorage.common.OperationType) ClusterService(org.apache.ignite.network.ClusterService) ServerUpdateMatcher.upd(org.apache.ignite.internal.metastorage.client.ItMetaStorageServiceTest.ServerUpdateMatcher.upd) NamedThreadFactory(org.apache.ignite.internal.thread.NamedThreadFactory) WorkDirectoryExtension(org.apache.ignite.internal.testframework.WorkDirectoryExtension) Collections(java.util.Collections) Update(org.apache.ignite.internal.metastorage.server.Update) IgniteUuid(org.apache.ignite.lang.IgniteUuid) ClusterService(org.apache.ignite.network.ClusterService) NetworkAddress(org.apache.ignite.network.NetworkAddress) StaticNodeFinder(org.apache.ignite.network.StaticNodeFinder) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) NamedThreadFactory(org.apache.ignite.internal.thread.NamedThreadFactory) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 28 with NetworkAddress

use of org.apache.ignite.network.NetworkAddress in project ignite-3 by apache.

the class ItTablePersistenceTest method afterFollowerStop.

/**
 * {@inheritDoc}
 */
@Override
public void afterFollowerStop(RaftGroupService service) throws Exception {
    TxManagerImpl 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));
    // Remove the first key
    table.delete(FIRST_KEY, null).get();
    // Put deleted data again
    table.upsert(FIRST_VALUE, null).get();
    txManager.stop();
}
Also used : TableStorage(org.apache.ignite.internal.storage.engine.TableStorage) HeapLockManager(org.apache.ignite.internal.tx.impl.HeapLockManager) InternalTableImpl(org.apache.ignite.internal.table.distributed.storage.InternalTableImpl) NetworkAddress(org.apache.ignite.network.NetworkAddress) TxManagerImpl(org.apache.ignite.internal.tx.impl.TxManagerImpl) TableTxManagerImpl(org.apache.ignite.internal.table.distributed.TableTxManagerImpl)

Example 29 with NetworkAddress

use of org.apache.ignite.network.NetworkAddress in project ignite-3 by apache.

the class ItTablePersistenceTest method beforeFollowerStop.

/**
 * {@inheritDoc}
 */
@Override
public void beforeFollowerStop(RaftGroupService service) throws Exception {
    TxManagerImpl 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(FIRST_VALUE, null).get();
}
Also used : TableStorage(org.apache.ignite.internal.storage.engine.TableStorage) HeapLockManager(org.apache.ignite.internal.tx.impl.HeapLockManager) InternalTableImpl(org.apache.ignite.internal.table.distributed.storage.InternalTableImpl) NetworkAddress(org.apache.ignite.network.NetworkAddress) TxManagerImpl(org.apache.ignite.internal.tx.impl.TxManagerImpl) TableTxManagerImpl(org.apache.ignite.internal.table.distributed.TableTxManagerImpl)

Example 30 with NetworkAddress

use of org.apache.ignite.network.NetworkAddress in project ignite-3 by apache.

the class ItTxDistributedTestSingleNode method before.

/**
 * Initialize the test state.
 */
@Override
@BeforeEach
public void before() throws Exception {
    int nodes = nodes();
    int replicas = replicas();
    assertTrue(nodes > 0);
    assertTrue(replicas > 0);
    List<NetworkAddress> localAddresses = findLocalAddresses(NODE_PORT_BASE, NODE_PORT_BASE + nodes);
    var nodeFinder = new StaticNodeFinder(localAddresses);
    nodeFinder.findNodes().parallelStream().map(addr -> startNode(testInfo, addr.toString(), addr.port(), nodeFinder)).forEach(cluster::add);
    for (ClusterService node : cluster) {
        assertTrue(waitForTopology(node, nodes, 1000));
    }
    log.info("The cluster has been started");
    if (startClient()) {
        client = startNode(testInfo, "client", NODE_PORT_BASE - 1, nodeFinder);
        assertTrue(waitForTopology(client, nodes + 1, 1000));
        log.info("The client has been started");
    }
    // Start raft servers. Each raft server can hold multiple groups.
    raftServers = new HashMap<>(nodes);
    txManagers = new HashMap<>(nodes);
    executor = new ScheduledThreadPoolExecutor(20, new NamedThreadFactory(Loza.CLIENT_POOL_NAME));
    for (int i = 0; i < nodes; i++) {
        var raftSrv = new Loza(cluster.get(i), workDir);
        raftSrv.start();
        ClusterNode node = cluster.get(i).topologyService().localMember();
        raftServers.put(node, raftSrv);
        TableTxManagerImpl txMgr = new TableTxManagerImpl(cluster.get(i), new HeapLockManager());
        txMgr.start();
        txManagers.put(node, txMgr);
    }
    log.info("Raft servers have been started");
    final String accountsName = "accounts";
    final String customersName = "customers";
    UUID accTblId = UUID.randomUUID();
    UUID custTblId = UUID.randomUUID();
    accRaftClients = startTable(accountsName, accTblId);
    custRaftClients = startTable(customersName, custTblId);
    log.info("Partition groups have been started");
    TxManager txMgr;
    if (startClient()) {
        txMgr = new TxManagerImpl(client, new HeapLockManager());
    } else {
        // Collocated mode.
        txMgr = txManagers.get(accRaftClients.get(0).clusterService().topologyService().localMember());
    }
    assertNotNull(txMgr);
    igniteTransactions = new IgniteTransactionsImpl(txMgr);
    this.accounts = new TableImpl(new InternalTableImpl(accountsName, accTblId, accRaftClients, 1, NetworkAddress::toString, txMgr, Mockito.mock(TableStorage.class)), new DummySchemaManagerImpl(ACCOUNTS_SCHEMA));
    this.customers = new TableImpl(new InternalTableImpl(customersName, custTblId, custRaftClients, 1, NetworkAddress::toString, txMgr, Mockito.mock(TableStorage.class)), new DummySchemaManagerImpl(CUSTOMERS_SCHEMA));
    log.info("Tables have been started");
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) TxAbstractTest(org.apache.ignite.internal.table.TxAbstractTest) RaftMessagesFactory(org.apache.ignite.raft.jraft.RaftMessagesFactory) RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) Map(java.util.Map) JraftServerImpl(org.apache.ignite.internal.raft.server.impl.JraftServerImpl) NodeFinder(org.apache.ignite.network.NodeFinder) Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) InternalTableImpl(org.apache.ignite.internal.table.distributed.storage.InternalTableImpl) Set(java.util.Set) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) TxManager(org.apache.ignite.internal.tx.TxManager) TestInfo(org.junit.jupiter.api.TestInfo) ClusterNode(org.apache.ignite.network.ClusterNode) List(java.util.List) StaticNodeFinder(org.apache.ignite.network.StaticNodeFinder) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) RaftGroupServiceImpl(org.apache.ignite.raft.jraft.rpc.impl.RaftGroupServiceImpl) ClusterServiceTestUtils.findLocalAddresses(org.apache.ignite.utils.ClusterServiceTestUtils.findLocalAddresses) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Assertions.fail(org.junit.jupiter.api.Assertions.fail) ConcurrentHashMapPartitionStorage(org.apache.ignite.internal.storage.basic.ConcurrentHashMapPartitionStorage) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) RendezvousAffinityFunction(org.apache.ignite.internal.affinity.RendezvousAffinityFunction) ClusterServiceTestUtils(org.apache.ignite.utils.ClusterServiceTestUtils) Loza(org.apache.ignite.internal.raft.Loza) HashMap(java.util.HashMap) VersionedRowStore(org.apache.ignite.internal.table.distributed.storage.VersionedRowStore) HeapLockManager(org.apache.ignite.internal.tx.impl.HeapLockManager) TestScaleCubeClusterServiceFactory(org.apache.ignite.network.scalecube.TestScaleCubeClusterServiceFactory) TestUtils.waitForTopology(org.apache.ignite.raft.jraft.test.TestUtils.waitForTopology) TableImpl(org.apache.ignite.internal.table.TableImpl) IgniteUtils(org.apache.ignite.internal.util.IgniteUtils) DummySchemaManagerImpl(org.apache.ignite.internal.table.impl.DummySchemaManagerImpl) TxManagerImpl(org.apache.ignite.internal.tx.impl.TxManagerImpl) TableTxManagerImpl(org.apache.ignite.internal.table.distributed.TableTxManagerImpl) TableStorage(org.apache.ignite.internal.storage.engine.TableStorage) NetworkAddress(org.apache.ignite.network.NetworkAddress) TimeUnit(java.util.concurrent.TimeUnit) Mockito(org.mockito.Mockito) Peer(org.apache.ignite.raft.client.Peer) AfterEach(org.junit.jupiter.api.AfterEach) ClusterService(org.apache.ignite.network.ClusterService) PartitionListener(org.apache.ignite.internal.table.distributed.raft.PartitionListener) IgniteTransactionsImpl(org.apache.ignite.internal.tx.impl.IgniteTransactionsImpl) NamedThreadFactory(org.apache.ignite.internal.thread.NamedThreadFactory) Table(org.apache.ignite.table.Table) ClusterNode(org.apache.ignite.network.ClusterNode) TableStorage(org.apache.ignite.internal.storage.engine.TableStorage) StaticNodeFinder(org.apache.ignite.network.StaticNodeFinder) IgniteTransactionsImpl(org.apache.ignite.internal.tx.impl.IgniteTransactionsImpl) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) NamedThreadFactory(org.apache.ignite.internal.thread.NamedThreadFactory) InternalTableImpl(org.apache.ignite.internal.table.distributed.storage.InternalTableImpl) TableImpl(org.apache.ignite.internal.table.TableImpl) TxManager(org.apache.ignite.internal.tx.TxManager) Loza(org.apache.ignite.internal.raft.Loza) DummySchemaManagerImpl(org.apache.ignite.internal.table.impl.DummySchemaManagerImpl) HeapLockManager(org.apache.ignite.internal.tx.impl.HeapLockManager) ClusterService(org.apache.ignite.network.ClusterService) InternalTableImpl(org.apache.ignite.internal.table.distributed.storage.InternalTableImpl) NetworkAddress(org.apache.ignite.network.NetworkAddress) TxManagerImpl(org.apache.ignite.internal.tx.impl.TxManagerImpl) TableTxManagerImpl(org.apache.ignite.internal.table.distributed.TableTxManagerImpl) TableTxManagerImpl(org.apache.ignite.internal.table.distributed.TableTxManagerImpl) UUID(java.util.UUID) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

NetworkAddress (org.apache.ignite.network.NetworkAddress)32 ClusterService (org.apache.ignite.network.ClusterService)18 RaftGroupService (org.apache.ignite.raft.client.service.RaftGroupService)12 StaticNodeFinder (org.apache.ignite.network.StaticNodeFinder)11 Peer (org.apache.ignite.raft.client.Peer)11 Test (org.junit.jupiter.api.Test)11 BeforeEach (org.junit.jupiter.api.BeforeEach)9 ClusterNode (org.apache.ignite.network.ClusterNode)8 List (java.util.List)7 ArrayList (java.util.ArrayList)6 ExecutionException (java.util.concurrent.ExecutionException)6 JraftServerImpl (org.apache.ignite.internal.raft.server.impl.JraftServerImpl)6 TestScaleCubeClusterServiceFactory (org.apache.ignite.network.scalecube.TestScaleCubeClusterServiceFactory)6 Path (java.nio.file.Path)5 CompletableFuture (java.util.concurrent.CompletableFuture)5 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)5 InternalTableImpl (org.apache.ignite.internal.table.distributed.storage.InternalTableImpl)5 NamedThreadFactory (org.apache.ignite.internal.thread.NamedThreadFactory)5 TxManager (org.apache.ignite.internal.tx.TxManager)5 PeerId (org.apache.ignite.raft.jraft.entity.PeerId)5