Search in sources :

Example 6 with DiscoverySpiCustomMessage

use of org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage 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 7 with DiscoverySpiCustomMessage

use of org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage 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)

Aggregations

DiscoverySpiCustomMessage (org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage)7 IgniteException (org.apache.ignite.IgniteException)4 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)4 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)3 DiscoveryCustomMessage (org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage)3 DiscoveryHook (org.apache.ignite.testframework.GridTestUtils.DiscoveryHook)3 IgniteEx (org.apache.ignite.internal.IgniteEx)2 GridDiscoveryManager (org.apache.ignite.internal.managers.discovery.GridDiscoveryManager)2 NullLogger (org.apache.ignite.logger.NullLogger)2 MarshallerContextTestImpl (org.apache.ignite.marshaller.MarshallerContextTestImpl)2 GridTestKernalContext (org.apache.ignite.testframework.junits.GridTestKernalContext)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 UUID (java.util.UUID)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 AssertionFailedError (junit.framework.AssertionFailedError)1 Ignite (org.apache.ignite.Ignite)1