Search in sources :

Example 1 with DiscoveryHook

use of org.apache.ignite.testframework.GridTestUtils.DiscoveryHook in project ignite by apache.

the class BinaryMetadataUpdatesFlowTest method startListening.

/**
     * @param idx Index.
     * @param deafClient Deaf client.
     * @param observedIds Observed ids.
     */
private void startListening(int idx, boolean deafClient, Set<Integer> observedIds) throws Exception {
    clientMode = true;
    ContinuousQuery qry = new ContinuousQuery();
    qry.setLocalListener(new CQListener(observedIds));
    if (deafClient) {
        applyDiscoveryHook = true;
        discoveryHook = new DiscoveryHook() {

            @Override
            public void handleDiscoveryMessage(DiscoverySpiCustomMessage msg) {
                DiscoveryCustomMessage customMsg = msg == null ? null : (DiscoveryCustomMessage) IgniteUtils.field(msg, "delegate");
                if (customMsg instanceof MetadataUpdateProposedMessage) {
                    if (((MetadataUpdateProposedMessage) customMsg).typeId() == BINARY_TYPE_ID)
                        GridTestUtils.setFieldValue(customMsg, "typeId", 1);
                } else if (customMsg instanceof MetadataUpdateAcceptedMessage) {
                    if (((MetadataUpdateAcceptedMessage) customMsg).typeId() == BINARY_TYPE_ID)
                        GridTestUtils.setFieldValue(customMsg, "typeId", 1);
                }
            }
        };
        IgniteEx client = startGrid(idx);
        client.cache(DEFAULT_CACHE_NAME).withKeepBinary().query(qry);
    } else {
        applyDiscoveryHook = false;
        IgniteEx client = startGrid(idx);
        client.cache(DEFAULT_CACHE_NAME).withKeepBinary().query(qry);
    }
}
Also used : DiscoverySpiCustomMessage(org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) IgniteEx(org.apache.ignite.internal.IgniteEx) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) DiscoveryHook(org.apache.ignite.testframework.GridTestUtils.DiscoveryHook)

Example 2 with DiscoveryHook

use of org.apache.ignite.testframework.GridTestUtils.DiscoveryHook in project ignite by apache.

the class GridCacheBinaryObjectMetadataExchangeMultinodeTest method getConfiguration.

/** {@inheritDoc} */
@Override
protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(gridName);
    if (applyDiscoveryHook) {
        final DiscoveryHook hook = discoveryHook != null ? discoveryHook : new DiscoveryHook();
        cfg.setDiscoverySpi(new TcpDiscoverySpi() {

            @Override
            public void setListener(@Nullable DiscoverySpiListener lsnr) {
                super.setListener(DiscoverySpiListenerWrapper.wrap(lsnr, hook));
            }
        });
    }
    ((TcpDiscoverySpi) cfg.getDiscoverySpi()).setIpFinder(ipFinder);
    cfg.setMarshaller(new BinaryMarshaller());
    cfg.setClientMode(clientMode);
    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
    ccfg.setCacheMode(CacheMode.REPLICATED);
    cfg.setCacheConfiguration(ccfg);
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) DiscoverySpiListener(org.apache.ignite.spi.discovery.DiscoverySpiListener) DiscoveryHook(org.apache.ignite.testframework.GridTestUtils.DiscoveryHook) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 3 with DiscoveryHook

use of org.apache.ignite.testframework.GridTestUtils.DiscoveryHook in project ignite by apache.

the class GridCacheBinaryObjectMetadataExchangeMultinodeTest method testReadRequestBlockedOnUpdatingMetadata.

/**
     * Verifies that if thread tries to read metadata with ongoing update it gets blocked
     * until acknowledge message arrives.
     */
public void testReadRequestBlockedOnUpdatingMetadata() throws Exception {
    applyDiscoveryHook = true;
    discoveryHook = new DiscoveryHook() {

        @Override
        public void handleDiscoveryMessage(DiscoverySpiCustomMessage msg) {
            DiscoveryCustomMessage customMsg = msg == null ? null : (DiscoveryCustomMessage) IgniteUtils.field(msg, "delegate");
            if (customMsg instanceof MetadataUpdateAcceptedMessage) {
                if (((MetadataUpdateAcceptedMessage) customMsg).typeId() == BINARY_TYPE_ID)
                    try {
                        Thread.sleep(300);
                    } catch (InterruptedException ignored) {
                    // No-op.
                    }
            }
        }
    };
    final IgniteEx ignite0 = startGrid(0);
    applyDiscoveryHook = false;
    final IgniteEx ignite1 = startGrid(1);
    final ErrorHolder errorHolder = new ErrorHolder();
    applyDiscoveryHook = true;
    discoveryHook = new DiscoveryHook() {

        private volatile IgniteEx ignite;

        @Override
        public void handleDiscoveryMessage(DiscoverySpiCustomMessage msg) {
            DiscoveryCustomMessage customMsg = msg == null ? null : (DiscoveryCustomMessage) IgniteUtils.field(msg, "delegate");
            if (customMsg instanceof MetadataUpdateAcceptedMessage) {
                MetadataUpdateAcceptedMessage acceptedMsg = (MetadataUpdateAcceptedMessage) customMsg;
                if (acceptedMsg.typeId() == BINARY_TYPE_ID && acceptedMsg.acceptedVersion() == 2) {
                    Object binaryProc = U.field(ignite.context(), "cacheObjProc");
                    Object transport = U.field(binaryProc, "transport");
                    try {
                        Map syncMap = U.field(transport, "syncMap");
                        int size = syncMap.size();
                        assertEquals("unexpected size of syncMap: ", 1, size);
                        Object syncKey = syncMap.keySet().iterator().next();
                        int typeId = U.field(syncKey, "typeId");
                        assertEquals("unexpected typeId: ", BINARY_TYPE_ID, typeId);
                        int ver = U.field(syncKey, "ver");
                        assertEquals("unexpected pendingVersion: ", 2, ver);
                    } catch (AssertionFailedError err) {
                        errorHolder.error(err);
                    }
                }
            }
        }

        @Override
        public void ignite(IgniteEx ignite) {
            this.ignite = ignite;
        }
    };
    final IgniteEx ignite2 = startGrid(2);
    discoveryHook.ignite(ignite2);
    ignite0.executorService().submit(new Runnable() {

        @Override
        public void run() {
            addIntField(ignite0, "f1", 101, 1);
        }
    }).get();
    UUID id2 = ignite2.localNode().id();
    ClusterGroup cg2 = ignite2.cluster().forNodeId(id2);
    Future<?> fut = ignite1.executorService().submit(new Runnable() {

        @Override
        public void run() {
            LATCH1.countDown();
            addStringField(ignite1, "f2", "str", 2);
        }
    });
    ignite2.compute(cg2).withAsync().call(new IgniteCallable<Object>() {

        @Override
        public Object call() throws Exception {
            try {
                LATCH1.await();
            } catch (InterruptedException ignored) {
            // No-op.
            }
            Object fieldVal = ((BinaryObject) ignite2.cache(DEFAULT_CACHE_NAME).withKeepBinary().get(1)).field("f1");
            return fieldVal;
        }
    });
    fut.get();
    if (!errorHolder.isEmpty())
        errorHolder.fail();
}
Also used : ClusterGroup(org.apache.ignite.cluster.ClusterGroup) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) DiscoverySpiCustomMessage(org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage) IgniteEx(org.apache.ignite.internal.IgniteEx) BinaryObject(org.apache.ignite.binary.BinaryObject) AssertionFailedError(junit.framework.AssertionFailedError) UUID(java.util.UUID) Map(java.util.Map) DiscoveryHook(org.apache.ignite.testframework.GridTestUtils.DiscoveryHook)

Example 4 with DiscoveryHook

use of org.apache.ignite.testframework.GridTestUtils.DiscoveryHook in project ignite by apache.

the class GridCacheBinaryObjectMetadataExchangeMultinodeTest method startDeafClient.

/**
     * Starts client node that skips <b>MetadataUpdateProposedMessage</b> and <b>MetadataUpdateAcceptedMessage</b>
     * messages.
     *
     * @param clientName name of client node.
     */
private Ignite startDeafClient(String clientName) throws Exception {
    clientMode = true;
    applyDiscoveryHook = true;
    discoveryHook = new DiscoveryHook() {

        @Override
        public void handleDiscoveryMessage(DiscoverySpiCustomMessage msg) {
            DiscoveryCustomMessage customMsg = msg == null ? null : (DiscoveryCustomMessage) IgniteUtils.field(msg, "delegate");
            if (customMsg instanceof MetadataUpdateProposedMessage) {
                if (((MetadataUpdateProposedMessage) customMsg).typeId() == BINARY_TYPE_ID)
                    GridTestUtils.setFieldValue(customMsg, "typeId", 1);
            } else if (customMsg instanceof MetadataUpdateAcceptedMessage) {
                if (((MetadataUpdateAcceptedMessage) customMsg).typeId() == BINARY_TYPE_ID)
                    GridTestUtils.setFieldValue(customMsg, "typeId", 1);
            }
        }
    };
    Ignite client = startGrid(clientName);
    clientMode = false;
    applyDiscoveryHook = false;
    return client;
}
Also used : DiscoverySpiCustomMessage(org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage) Ignite(org.apache.ignite.Ignite) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) DiscoveryHook(org.apache.ignite.testframework.GridTestUtils.DiscoveryHook)

Example 5 with DiscoveryHook

use of org.apache.ignite.testframework.GridTestUtils.DiscoveryHook in project ignite by apache.

the class BinaryMetadataUpdatesFlowTest method getConfiguration.

/** {@inheritDoc} */
@Override
protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(gridName);
    cfg.setPeerClassLoadingEnabled(false);
    if (applyDiscoveryHook) {
        final DiscoveryHook hook = discoveryHook != null ? discoveryHook : new DiscoveryHook();
        TcpDiscoverySpi discoSpi = new TcpDiscoverySpi() {

            @Override
            public void setListener(@Nullable DiscoverySpiListener lsnr) {
                super.setListener(GridTestUtils.DiscoverySpiListenerWrapper.wrap(lsnr, hook));
            }
        };
        cfg.setDiscoverySpi(discoSpi);
        cfg.setMetricsUpdateFrequency(1000);
    }
    ((TcpDiscoverySpi) cfg.getDiscoverySpi()).setIpFinder(ipFinder);
    cfg.setMarshaller(new BinaryMarshaller());
    cfg.setClientMode(clientMode);
    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
    ccfg.setCacheMode(CacheMode.REPLICATED);
    cfg.setCacheConfiguration(ccfg);
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) DiscoverySpiListener(org.apache.ignite.spi.discovery.DiscoverySpiListener) DiscoveryHook(org.apache.ignite.testframework.GridTestUtils.DiscoveryHook) Nullable(org.jetbrains.annotations.Nullable) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Aggregations

DiscoveryHook (org.apache.ignite.testframework.GridTestUtils.DiscoveryHook)5 DiscoveryCustomMessage (org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage)3 DiscoverySpiCustomMessage (org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage)3 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)2 IgniteEx (org.apache.ignite.internal.IgniteEx)2 BinaryMarshaller (org.apache.ignite.internal.binary.BinaryMarshaller)2 DiscoverySpiListener (org.apache.ignite.spi.discovery.DiscoverySpiListener)2 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)2 Map (java.util.Map)1 UUID (java.util.UUID)1 AssertionFailedError (junit.framework.AssertionFailedError)1 Ignite (org.apache.ignite.Ignite)1 BinaryObject (org.apache.ignite.binary.BinaryObject)1 ContinuousQuery (org.apache.ignite.cache.query.ContinuousQuery)1 ClusterGroup (org.apache.ignite.cluster.ClusterGroup)1 Nullable (org.jetbrains.annotations.Nullable)1