Search in sources :

Example 21 with GridTestNode

use of org.apache.ignite.testframework.GridTestNode in project ignite by apache.

the class GridTcpCommunicationSpiRecoverySelfTest method startSpis.

/**
     * @throws Exception If failed.
     */
private void startSpis() throws Exception {
    spis.clear();
    nodes.clear();
    spiRsrcs.clear();
    Map<ClusterNode, GridSpiTestContext> ctxs = new HashMap<>();
    for (int i = 0; i < SPI_CNT; i++) {
        TcpCommunicationSpi spi = getSpi(i);
        GridTestUtils.setFieldValue(spi, IgniteSpiAdapter.class, "igniteInstanceName", "grid-" + i);
        IgniteTestResources rsrcs = new IgniteTestResources();
        GridTestNode node = new GridTestNode(rsrcs.getNodeId());
        node.order(i);
        GridSpiTestContext ctx = initSpiContext();
        ctx.setLocalNode(node);
        spiRsrcs.add(rsrcs);
        rsrcs.inject(spi);
        if (useSsl) {
            IgniteMock ignite = GridTestUtils.getFieldValue(spi, IgniteSpiAdapter.class, "ignite");
            IgniteConfiguration cfg = ignite.configuration().setSslContextFactory(GridTestUtils.sslFactory());
            ignite.setStaticCfg(cfg);
        }
        spi.setListener(new TestListener());
        node.setAttributes(spi.getNodeAttributes());
        nodes.add(node);
        spi.spiStart(getTestIgniteInstanceName() + (i + 1));
        spis.add(spi);
        spi.onContextInitialized(ctx);
        ctxs.put(node, ctx);
    }
    // For each context set remote nodes.
    for (Map.Entry<ClusterNode, GridSpiTestContext> e : ctxs.entrySet()) {
        for (ClusterNode n : nodes) {
            if (!n.equals(e.getKey()))
                e.getValue().remoteNodes().add(n);
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridSpiTestContext(org.apache.ignite.testframework.GridSpiTestContext) HashMap(java.util.HashMap) GridTestNode(org.apache.ignite.testframework.GridTestNode) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteTestResources(org.apache.ignite.testframework.junits.IgniteTestResources) IgniteMock(org.apache.ignite.testframework.junits.IgniteMock) HashMap(java.util.HashMap) Map(java.util.Map)

Example 22 with GridTestNode

use of org.apache.ignite.testframework.GridTestNode in project ignite by apache.

the class IgniteTcpCommunicationRecoveryAckClosureSelfTest method startSpis.

/**
     * @param ackCnt Recovery acknowledgement count.
     * @param idleTimeout Idle connection timeout.
     * @param queueLimit Message queue limit.
     * @throws Exception If failed.
     */
private void startSpis(int ackCnt, int idleTimeout, int queueLimit) throws Exception {
    spis.clear();
    nodes.clear();
    spiRsrcs.clear();
    Map<ClusterNode, GridSpiTestContext> ctxs = new HashMap<>();
    for (int i = 0; i < SPI_CNT; i++) {
        TcpCommunicationSpi spi = getSpi(ackCnt, idleTimeout, queueLimit);
        GridTestUtils.setFieldValue(spi, IgniteSpiAdapter.class, "igniteInstanceName", "grid-" + i);
        IgniteTestResources rsrcs = new IgniteTestResources();
        GridTestNode node = new GridTestNode(rsrcs.getNodeId());
        GridSpiTestContext ctx = initSpiContext();
        ctx.setLocalNode(node);
        spiRsrcs.add(rsrcs);
        rsrcs.inject(spi);
        spi.setListener(new TestListener());
        node.setAttributes(spi.getNodeAttributes());
        nodes.add(node);
        spi.spiStart(getTestIgniteInstanceName() + (i + 1));
        spis.add(spi);
        spi.onContextInitialized(ctx);
        ctxs.put(node, ctx);
    }
    // For each context set remote nodes.
    for (Map.Entry<ClusterNode, GridSpiTestContext> e : ctxs.entrySet()) {
        for (ClusterNode n : nodes) {
            if (!n.equals(e.getKey()))
                e.getValue().remoteNodes().add(n);
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridSpiTestContext(org.apache.ignite.testframework.GridSpiTestContext) HashMap(java.util.HashMap) IgniteTestResources(org.apache.ignite.testframework.junits.IgniteTestResources) HashMap(java.util.HashMap) Map(java.util.Map) GridTestNode(org.apache.ignite.testframework.GridTestNode)

Example 23 with GridTestNode

use of org.apache.ignite.testframework.GridTestNode in project ignite by apache.

the class GridSpiAbstractTest method initSpiContext.

/**
     * @return SPI context.
     * @throws Exception If anything failed.
     */
protected GridSpiTestContext initSpiContext() throws Exception {
    GridSpiTestContext spiCtx = new GridSpiTestContext();
    if (getTestData().getDiscoverySpi() != null) {
        spiCtx.setLocalNode(getTestData().getDiscoverySpi().getLocalNode());
        for (ClusterNode node : getTestData().getDiscoverySpi().getRemoteNodes()) spiCtx.addNode(node);
    } else {
        GridTestNode node = new GridTestNode(UUID.randomUUID());
        spiCtx.setLocalNode(node);
        if (getSpi() != null) {
            // Set up SPI class name and SPI version.
            Map<String, Serializable> attrs = initSpiClassAndVersionAttributes(getSpi());
            for (Map.Entry<String, Serializable> entry : attrs.entrySet()) node.addAttribute(entry.getKey(), entry.getValue());
        }
    }
    return spiCtx;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridSpiTestContext(org.apache.ignite.testframework.GridSpiTestContext) Serializable(java.io.Serializable) IgniteProductVersion.fromString(org.apache.ignite.lang.IgniteProductVersion.fromString) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) GridTestNode(org.apache.ignite.testframework.GridTestNode)

Example 24 with GridTestNode

use of org.apache.ignite.testframework.GridTestNode in project ignite by apache.

the class GridCommonAbstractTest method movingKeysAfterJoin.

/**
     * Return list of keys that are primary for given node on current topology,
     * but primary node will change after new node will be added.
     *
     * @param ign Ignite.
     * @param cacheName Cache name.
     * @param size Number of keys.
     * @return List of keys.
     */
protected final List<Integer> movingKeysAfterJoin(Ignite ign, String cacheName, int size) {
    assertEquals("Expected consistentId is set to node name", ign.name(), ign.cluster().localNode().consistentId());
    GridCacheContext<Object, Object> cctx = ((IgniteKernal) ign).context().cache().internalCache(cacheName).context();
    ArrayList<ClusterNode> nodes = new ArrayList<>(ign.cluster().nodes());
    AffinityFunction func = cctx.config().getAffinity();
    AffinityFunctionContext ctx = new GridAffinityFunctionContextImpl(nodes, null, null, AffinityTopologyVersion.NONE, cctx.config().getBackups());
    List<List<ClusterNode>> calcAff = func.assignPartitions(ctx);
    GridTestNode fakeNode = new GridTestNode(UUID.randomUUID(), null);
    fakeNode.consistentId(getTestIgniteInstanceName(nodes.size()));
    nodes.add(fakeNode);
    ctx = new GridAffinityFunctionContextImpl(nodes, null, null, AffinityTopologyVersion.NONE, cctx.config().getBackups());
    List<List<ClusterNode>> calcAff2 = func.assignPartitions(ctx);
    Set<Integer> movedParts = new HashSet<>();
    UUID locId = ign.cluster().localNode().id();
    for (int i = 0; i < calcAff.size(); i++) {
        if (calcAff.get(i).get(0).id().equals(locId) && !calcAff2.get(i).get(0).id().equals(locId))
            movedParts.add(i);
    }
    List<Integer> keys = new ArrayList<>();
    Affinity<Integer> aff = ign.affinity(cacheName);
    for (int i = 0; i < 10_000; i++) {
        int keyPart = aff.partition(i);
        if (movedParts.contains(keyPart)) {
            keys.add(i);
            if (keys.size() == size)
                break;
        }
    }
    assertEquals("Failed to find moving keys [movedPats=" + movedParts + ", keys=" + keys + ']', size, keys.size());
    return keys;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) ArrayList(java.util.ArrayList) AffinityFunctionContext(org.apache.ignite.cache.affinity.AffinityFunctionContext) GridTestNode(org.apache.ignite.testframework.GridTestNode) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridAffinityFunctionContextImpl(org.apache.ignite.internal.processors.affinity.GridAffinityFunctionContextImpl) List(java.util.List) ArrayList(java.util.ArrayList) UUID(java.util.UUID) AffinityFunction(org.apache.ignite.cache.affinity.AffinityFunction) HashSet(java.util.HashSet)

Example 25 with GridTestNode

use of org.apache.ignite.testframework.GridTestNode in project ignite by apache.

the class GridAbstractCommunicationSelfTest method startSpis.

/**
     * @throws Exception If failed.
     */
private void startSpis() throws Exception {
    spis.clear();
    nodes.clear();
    spiRsrcs.clear();
    Map<ClusterNode, GridSpiTestContext> ctxs = new HashMap<>();
    for (int i = 0; i < getSpiCount(); i++) {
        CommunicationSpi<Message> spi = getSpi(i);
        GridTestUtils.setFieldValue(spi, IgniteSpiAdapter.class, "igniteInstanceName", "grid-" + i);
        IgniteTestResources rsrcs = new IgniteTestResources();
        GridTestNode node = new GridTestNode(rsrcs.getNodeId());
        node.order(i);
        GridSpiTestContext ctx = initSpiContext();
        ctx.setLocalNode(node);
        info(">>> Initialized context: nodeId=" + ctx.localNode().id());
        spiRsrcs.add(rsrcs);
        rsrcs.inject(spi);
        if (useSsl) {
            IgniteMock ignite = GridTestUtils.getFieldValue(spi, IgniteSpiAdapter.class, "ignite");
            IgniteConfiguration cfg = ignite.configuration().setSslContextFactory(GridTestUtils.sslFactory());
            ignite.setStaticCfg(cfg);
        }
        spi.setListener(new MessageListener(rsrcs.getNodeId()));
        node.setAttributes(spi.getNodeAttributes());
        node.setAttribute(ATTR_MACS, F.concat(U.allLocalMACs(), ", "));
        nodes.add(node);
        spi.spiStart(getTestIgniteInstanceName() + (i + 1));
        spis.put(rsrcs.getNodeId(), spi);
        spi.onContextInitialized(ctx);
        ctxs.put(node, ctx);
    }
    // For each context set remote nodes.
    for (Entry<ClusterNode, GridSpiTestContext> e : ctxs.entrySet()) {
        for (ClusterNode n : nodes) {
            if (!n.equals(e.getKey()))
                e.getValue().remoteNodes().add(n);
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridSpiTestContext(org.apache.ignite.testframework.GridSpiTestContext) Message(org.apache.ignite.plugin.extensions.communication.Message) HashMap(java.util.HashMap) GridTestNode(org.apache.ignite.testframework.GridTestNode) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteTestResources(org.apache.ignite.testframework.junits.IgniteTestResources) IgniteMock(org.apache.ignite.testframework.junits.IgniteMock)

Aggregations

GridTestNode (org.apache.ignite.testframework.GridTestNode)43 ClusterNode (org.apache.ignite.cluster.ClusterNode)27 GridSpiTestContext (org.apache.ignite.testframework.GridSpiTestContext)17 GridTestTaskSession (org.apache.ignite.GridTestTaskSession)14 ArrayList (java.util.ArrayList)11 GridTestJob (org.apache.ignite.GridTestJob)9 HashMap (java.util.HashMap)7 IgniteTestResources (org.apache.ignite.testframework.junits.IgniteTestResources)7 Map (java.util.Map)5 GridTestJobResult (org.apache.ignite.GridTestJobResult)5 GridFailoverTestContext (org.apache.ignite.spi.failover.GridFailoverTestContext)5 Serializable (java.io.Serializable)4 List (java.util.List)4 ComputeTaskSession (org.apache.ignite.compute.ComputeTaskSession)4 ClusterMetricsSnapshot (org.apache.ignite.internal.ClusterMetricsSnapshot)4 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)3 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)3 GridAffinityFunctionContextImpl (org.apache.ignite.internal.processors.affinity.GridAffinityFunctionContextImpl)3 Message (org.apache.ignite.plugin.extensions.communication.Message)3 CollisionJobContext (org.apache.ignite.spi.collision.CollisionJobContext)3