Search in sources :

Example 1 with TestRecordingCommunicationSpi

use of org.apache.ignite.internal.TestRecordingCommunicationSpi in project ignite by apache.

the class IgniteCacheReadFromBackupTest method recordGetRequests.

/**
     * @param ignite Node.
     * @param near Near cache flag.
     * @return Communication SPI.
     */
private TestRecordingCommunicationSpi recordGetRequests(Ignite ignite, boolean near) {
    TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi) ignite.configuration().getCommunicationSpi();
    spi.record(near ? GridNearGetRequest.class : GridNearSingleGetRequest.class);
    return spi;
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) GridNearSingleGetRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearSingleGetRequest) GridNearGetRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearGetRequest)

Example 2 with TestRecordingCommunicationSpi

use of org.apache.ignite.internal.TestRecordingCommunicationSpi in project ignite by apache.

the class IgniteCacheReadFromBackupTest method testGetFromBackupStoreReadThroughEnabled.

/**
     * @throws Exception If failed.
     */
public void testGetFromBackupStoreReadThroughEnabled() throws Exception {
    for (CacheConfiguration<Object, Object> ccfg : cacheConfigurations()) {
        ccfg.setCacheStoreFactory(new TestStoreFactory());
        ccfg.setReadThrough(true);
        boolean near = (ccfg.getNearConfiguration() != null);
        log.info("Test cache [mode=" + ccfg.getCacheMode() + ", atomicity=" + ccfg.getAtomicityMode() + ", backups=" + ccfg.getBackups() + ", near=" + near + "]");
        ignite(0).createCache(ccfg);
        awaitPartitionMapExchange();
        try {
            for (int i = 0; i < NODES; i++) {
                Ignite ignite = ignite(i);
                log.info("Check node: " + ignite.name());
                IgniteCache<Integer, Integer> cache = ignite.cache(ccfg.getName());
                TestRecordingCommunicationSpi spi = recordGetRequests(ignite, near);
                Integer key = backupKey(cache);
                assertNull(cache.get(key));
                List<Object> msgs = spi.recordedMessages(false);
                assertEquals(1, msgs.size());
            }
        } finally {
            ignite(0).destroyCache(ccfg.getName());
        }
    }
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) Ignite(org.apache.ignite.Ignite)

Example 3 with TestRecordingCommunicationSpi

use of org.apache.ignite.internal.TestRecordingCommunicationSpi in project ignite by apache.

the class IgniteCacheReadFromBackupTest method checkLocalRead.

/**
     * @param nodes Number of nodes.
     * @param ccfg Cache configuration.
     * @throws Exception If failed.
     */
private void checkLocalRead(int nodes, CacheConfiguration<Object, Object> ccfg) throws Exception {
    for (int i = 0; i < nodes; i++) {
        Ignite ignite = ignite(i);
        log.info("Check node: " + ignite.name());
        IgniteCache<Integer, Integer> cache = ignite.cache(ccfg.getName());
        List<Integer> backupKeys = backupKeys(cache, 2, 0);
        Integer backupKey = backupKeys.get(0);
        Integer nearKey = ccfg.getCacheMode() == PARTITIONED ? nearKey(cache) : null;
        checkLocalRead(ignite, ccfg, backupKey, nearKey);
        Set<Integer> keys = new HashSet<>(backupKeys);
        Map<Integer, Integer> vals = cache.getAll(keys);
        for (Integer key : keys) assertNull(vals.get(key));
        TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi) ignite.configuration().getCommunicationSpi();
        List<Object> msgs = spi.recordedMessages(false);
        assertEquals(0, msgs.size());
    }
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) Ignite(org.apache.ignite.Ignite) HashSet(java.util.HashSet)

Example 4 with TestRecordingCommunicationSpi

use of org.apache.ignite.internal.TestRecordingCommunicationSpi in project ignite by apache.

the class IgniteTxCachePrimarySyncTest method checkOnePhaseMessages.

/**
     * @param client Node executing cache operation.
     * @param ccfg Cache configuration.
     * @param c Cache update closure.
     * @throws Exception If failed.
     */
private void checkOnePhaseMessages(Ignite client, final CacheConfiguration<Object, Object> ccfg, final IgniteBiInClosure<Integer, IgniteCache<Object, Object>> c) throws Exception {
    Ignite ignite = ignite(0);
    assertNotSame(ignite, client);
    TestRecordingCommunicationSpi commSpiClient = (TestRecordingCommunicationSpi) client.configuration().getCommunicationSpi();
    TestRecordingCommunicationSpi commSpi0 = (TestRecordingCommunicationSpi) ignite.configuration().getCommunicationSpi();
    IgniteCache<Object, Object> cache = ignite.cache(ccfg.getName());
    final Integer key = primaryKey(cache);
    cache.remove(key);
    waitKeyRemoved(ccfg.getName(), key);
    final IgniteCache<Object, Object> clientCache = client.cache(ccfg.getName());
    commSpi0.record(GridNearTxFinishResponse.class, GridNearTxPrepareResponse.class);
    commSpiClient.record(GridNearTxPrepareRequest.class, GridNearTxFinishRequest.class);
    c.apply(key, clientCache);
    List<Object> srvMsgs = commSpi0.recordedMessages(true);
    assertEquals("Unexpected messages: " + srvMsgs, 1, srvMsgs.size());
    assertTrue("Unexpected message: " + srvMsgs.get(0), srvMsgs.get(0) instanceof GridNearTxPrepareResponse);
    List<Object> clientMsgs = commSpiClient.recordedMessages(true);
    assertEquals("Unexpected messages: " + clientMsgs, 1, clientMsgs.size());
    assertTrue("Unexpected message: " + clientMsgs.get(0), clientMsgs.get(0) instanceof GridNearTxPrepareRequest);
    GridNearTxPrepareRequest req = (GridNearTxPrepareRequest) clientMsgs.get(0);
    assertTrue(req.onePhaseCommit());
    for (Ignite ignite0 : G.allGrids()) assertEquals(key, ignite0.cache(cache.getName()).get(key));
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) GridNearTxPrepareResponse(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxPrepareResponse) Ignite(org.apache.ignite.Ignite) GridNearTxPrepareRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxPrepareRequest)

Example 5 with TestRecordingCommunicationSpi

use of org.apache.ignite.internal.TestRecordingCommunicationSpi in project ignite by apache.

the class IgniteCacheSingleGetMessageTest method checkSingleGetMessage.

/**
     * @param cache Cache.
     * @param key Key.
     * @param backup {@code True} if given key is backup key.
     * @throws Exception If failed.
     */
@SuppressWarnings("unchecked")
private void checkSingleGetMessage(IgniteCache<Integer, Integer> cache, Integer key, boolean backup) throws Exception {
    CacheConfiguration<Integer, Integer> ccfg = cache.getConfiguration(CacheConfiguration.class);
    Ignite node = cache.unwrap(Ignite.class);
    TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi) node.configuration().getCommunicationSpi();
    spi.record(GridNearSingleGetRequest.class);
    Ignite primary = primaryNode(key, cache.getName());
    assertNotSame(node, primary);
    TestRecordingCommunicationSpi primarySpi = (TestRecordingCommunicationSpi) primary.configuration().getCommunicationSpi();
    primarySpi.record(GridNearSingleGetResponse.class);
    assertNull(cache.get(key));
    if (backup)
        checkNoMessages(spi, primarySpi);
    else
        checkMessages(spi, primarySpi);
    assertFalse(cache.containsKey(key));
    if (backup)
        checkNoMessages(spi, primarySpi);
    else
        checkMessages(spi, primarySpi);
    cache.put(key, 1);
    assertNotNull(cache.get(key));
    if (backup)
        checkNoMessages(spi, primarySpi);
    else
        checkMessages(spi, primarySpi);
    assertTrue(cache.containsKey(key));
    if (backup)
        checkNoMessages(spi, primarySpi);
    else
        checkMessages(spi, primarySpi);
    if (ccfg.getAtomicityMode() == TRANSACTIONAL) {
        cache.remove(key);
        try (Transaction tx = node.transactions().txStart(OPTIMISTIC, REPEATABLE_READ)) {
            assertNull(cache.get(key));
            tx.commit();
        }
        if (backup)
            checkNoMessages(spi, primarySpi);
        else
            checkMessages(spi, primarySpi);
        try (Transaction tx = node.transactions().txStart(OPTIMISTIC, REPEATABLE_READ)) {
            assertFalse(cache.containsKey(key));
            tx.commit();
        }
        if (backup)
            checkNoMessages(spi, primarySpi);
        else
            checkMessages(spi, primarySpi);
        cache.put(key, 1);
        try (Transaction tx = node.transactions().txStart(OPTIMISTIC, REPEATABLE_READ)) {
            assertNotNull(cache.get(key));
            tx.commit();
        }
        if (backup)
            checkNoMessages(spi, primarySpi);
        else
            checkMessages(spi, primarySpi);
        try (Transaction tx = node.transactions().txStart(OPTIMISTIC, REPEATABLE_READ)) {
            assertTrue(cache.containsKey(key));
            tx.commit();
        }
        if (backup)
            checkNoMessages(spi, primarySpi);
        else
            checkMessages(spi, primarySpi);
    }
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) Transaction(org.apache.ignite.transactions.Transaction) Ignite(org.apache.ignite.Ignite)

Aggregations

TestRecordingCommunicationSpi (org.apache.ignite.internal.TestRecordingCommunicationSpi)41 Ignite (org.apache.ignite.Ignite)25 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)11 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)10 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)9 ClusterNode (org.apache.ignite.cluster.ClusterNode)8 Message (org.apache.ignite.plugin.extensions.communication.Message)7 GridDhtPartitionsSingleMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage)5 GridDhtPartitionsFullMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage)4 ArrayList (java.util.ArrayList)3 GridIoMessage (org.apache.ignite.internal.managers.communication.GridIoMessage)3 GridDhtPartitionSupplyMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage)3 Transaction (org.apache.ignite.transactions.Transaction)3 List (java.util.List)2 CacheLoaderException (javax.cache.integration.CacheLoaderException)2 CacheWriterException (javax.cache.integration.CacheWriterException)2 IgniteException (org.apache.ignite.IgniteException)2 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)2 ClusterTopologyServerNotFoundException (org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException)2 DiscoveryCustomMessage (org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage)2