Search in sources :

Example 11 with CacheStore

use of org.apache.ignite.cache.store.CacheStore in project ignite by apache.

the class DataStreamProcessorSelfTest method getConfiguration.

/** {@inheritDoc} */
@SuppressWarnings({ "IfMayBeConditional", "unchecked" })
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    cfg.setPeerClassLoadingEnabled(false);
    TcpDiscoverySpi spi = new TcpDiscoverySpi();
    spi.setForceServerMode(true);
    spi.setIpFinder(ipFinder);
    cfg.setDiscoverySpi(spi);
    cfg.setIncludeProperties();
    if (useCache) {
        CacheConfiguration cc = defaultCacheConfiguration();
        cc.setCacheMode(mode);
        cc.setAtomicityMode(TRANSACTIONAL);
        if (nearEnabled) {
            NearCacheConfiguration nearCfg = new NearCacheConfiguration();
            cc.setNearConfiguration(nearCfg);
        }
        cc.setWriteSynchronizationMode(FULL_SYNC);
        if (store != null) {
            cc.setCacheStoreFactory(new IgniteReflectionFactory<CacheStore>(TestStore.class));
            cc.setReadThrough(true);
            cc.setWriteThrough(true);
        }
        cfg.setCacheConfiguration(cc);
    } else {
        cfg.setCacheConfiguration();
        cfg.setClientMode(true);
    }
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) CacheStore(org.apache.ignite.cache.store.CacheStore) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration)

Example 12 with CacheStore

use of org.apache.ignite.cache.store.CacheStore in project ignite by apache.

the class GridCacheColocatedDebugTest method checkStore.

/**
     * @param ignite Grid to take store from.
     * @param map Expected values in store.
     * @throws Exception If failed.
     */
private void checkStore(Ignite ignite, Map<Integer, String> map) throws Exception {
    String cacheName = ignite.configuration().getCacheConfiguration()[0].getName();
    GridCacheContext ctx = ((IgniteKernal) grid()).context().cache().internalCache(cacheName).context();
    CacheStore store = ctx.store().configuredStore();
    assertEquals(map, ((GridCacheTestStore) store).getMap());
}
Also used : GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) CacheStore(org.apache.ignite.cache.store.CacheStore)

Example 13 with CacheStore

use of org.apache.ignite.cache.store.CacheStore in project ignite by apache.

the class GridCacheWriteBehindStorePartitionedMultiNodeSelfTest method getConfiguration.

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration c = super.getConfiguration(igniteInstanceName);
    TcpDiscoverySpi disco = new TcpDiscoverySpi();
    disco.setIpFinder(ipFinder);
    c.setDiscoverySpi(disco);
    CacheConfiguration cc = defaultCacheConfiguration();
    cc.setCacheMode(CacheMode.PARTITIONED);
    cc.setWriteBehindEnabled(true);
    cc.setWriteBehindFlushFrequency(WRITE_BEHIND_FLUSH_FREQ);
    cc.setAtomicityMode(TRANSACTIONAL);
    cc.setNearConfiguration(new NearCacheConfiguration());
    CacheStore store = stores[idx.getAndIncrement()] = new GridCacheTestStore();
    cc.setCacheStoreFactory(singletonFactory(store));
    cc.setReadThrough(true);
    cc.setWriteThrough(true);
    cc.setLoadPreviousValue(true);
    c.setCacheConfiguration(cc);
    return c;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) CacheStore(org.apache.ignite.cache.store.CacheStore) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) GridCacheTestStore(org.apache.ignite.internal.processors.cache.GridCacheTestStore)

Example 14 with CacheStore

use of org.apache.ignite.cache.store.CacheStore in project ignite by apache.

the class IgnitePersistentStoreTest method pojoStrategyTransactionTest.

/** */
@SuppressWarnings("unchecked")
private void pojoStrategyTransactionTest(Ignite ignite, TransactionConcurrency concurrency, TransactionIsolation isolation) {
    LOGGER.info("-----------------------------------------------------------------------------------");
    LOGGER.info("Running POJO transaction tests using " + concurrency + " concurrency and " + isolation + " isolation level");
    LOGGER.info("-----------------------------------------------------------------------------------");
    CacheStore productStore = CacheStoreHelper.createCacheStore("product", new ClassPathResource("org/apache/ignite/tests/persistence/pojo/product.xml"), CassandraHelper.getAdminDataSrc());
    CacheStore orderStore = CacheStoreHelper.createCacheStore("order", new ClassPathResource("org/apache/ignite/tests/persistence/pojo/order.xml"), CassandraHelper.getAdminDataSrc());
    Map<Long, Product> productsMap = TestsHelper.generateProductsMap(5);
    Map<Long, Product> productsMap1;
    Map<Long, ProductOrder> ordersMap = TestsHelper.generateOrdersMap(5);
    Map<Long, ProductOrder> ordersMap1;
    Product product = TestsHelper.generateRandomProduct(-1L);
    ProductOrder order = TestsHelper.generateRandomOrder(-1L, -1L, new Date());
    IgniteTransactions txs = ignite.transactions();
    IgniteCache<Long, Product> productCache = ignite.getOrCreateCache(new CacheConfiguration<Long, Product>("product"));
    IgniteCache<Long, ProductOrder> orderCache = ignite.getOrCreateCache(new CacheConfiguration<Long, ProductOrder>("order"));
    LOGGER.info("Running POJO strategy write tests");
    LOGGER.info("Running single operation write tests");
    Transaction tx = txs.txStart(concurrency, isolation);
    try {
        productCache.put(product.getId(), product);
        orderCache.put(order.getId(), order);
        if (productStore.load(product.getId()) != null || orderStore.load(order.getId()) != null) {
            throw new RuntimeException("Single write operation test failed. Transaction wasn't committed yet, but " + "objects were already persisted into Cassandra");
        }
        Map<Long, Product> products = (Map<Long, Product>) productStore.loadAll(productsMap.keySet());
        Map<Long, ProductOrder> orders = (Map<Long, ProductOrder>) orderStore.loadAll(ordersMap.keySet());
        if ((products != null && !products.isEmpty()) || (orders != null && !orders.isEmpty())) {
            throw new RuntimeException("Single write operation test failed. Transaction wasn't committed yet, but " + "objects were already persisted into Cassandra");
        }
        tx.commit();
    } finally {
        U.closeQuiet(tx);
    }
    Product product1 = (Product) productStore.load(product.getId());
    ProductOrder order1 = (ProductOrder) orderStore.load(order.getId());
    if (product1 == null || order1 == null) {
        throw new RuntimeException("Single write operation test failed. Transaction was committed, but " + "no objects were persisted into Cassandra");
    }
    if (!product.equals(product1) || !order.equals(order1)) {
        throw new RuntimeException("Single write operation test failed. Transaction was committed, but " + "objects were incorrectly persisted/loaded to/from Cassandra");
    }
    LOGGER.info("Single operation write tests passed");
    LOGGER.info("Running bulk operation write tests");
    tx = txs.txStart(concurrency, isolation);
    try {
        productCache.putAll(productsMap);
        orderCache.putAll(ordersMap);
        productsMap1 = (Map<Long, Product>) productStore.loadAll(productsMap.keySet());
        ordersMap1 = (Map<Long, ProductOrder>) orderStore.loadAll(ordersMap.keySet());
        if ((productsMap1 != null && !productsMap1.isEmpty()) || (ordersMap1 != null && !ordersMap1.isEmpty())) {
            throw new RuntimeException("Bulk write operation test failed. Transaction wasn't committed yet, but " + "objects were already persisted into Cassandra");
        }
        tx.commit();
    } finally {
        U.closeQuiet(tx);
    }
    productsMap1 = (Map<Long, Product>) productStore.loadAll(productsMap.keySet());
    ordersMap1 = (Map<Long, ProductOrder>) orderStore.loadAll(ordersMap.keySet());
    if (productsMap1 == null || productsMap1.isEmpty() || ordersMap1 == null || ordersMap1.isEmpty()) {
        throw new RuntimeException("Bulk write operation test failed. Transaction was committed, but " + "no objects were persisted into Cassandra");
    }
    if (productsMap1.size() < productsMap.size() || ordersMap1.size() < ordersMap.size()) {
        throw new RuntimeException("Bulk write operation test failed. There were committed less objects " + "into Cassandra than expected");
    }
    if (productsMap1.size() > productsMap.size() || ordersMap1.size() > ordersMap.size()) {
        throw new RuntimeException("Bulk write operation test failed. There were committed more objects " + "into Cassandra than expected");
    }
    for (Map.Entry<Long, Product> entry : productsMap.entrySet()) {
        product = productsMap1.get(entry.getKey());
        if (!entry.getValue().equals(product)) {
            throw new RuntimeException("Bulk write operation test failed. Transaction was committed, but " + "some objects were incorrectly persisted/loaded to/from Cassandra");
        }
    }
    for (Map.Entry<Long, ProductOrder> entry : ordersMap.entrySet()) {
        order = ordersMap1.get(entry.getKey());
        if (!entry.getValue().equals(order)) {
            throw new RuntimeException("Bulk write operation test failed. Transaction was committed, but " + "some objects were incorrectly persisted/loaded to/from Cassandra");
        }
    }
    LOGGER.info("Bulk operation write tests passed");
    LOGGER.info("POJO strategy write tests passed");
    LOGGER.info("Running POJO strategy delete tests");
    LOGGER.info("Running single delete tests");
    tx = txs.txStart(concurrency, isolation);
    try {
        productCache.remove(-1L);
        orderCache.remove(-1L);
        if (productStore.load(-1L) == null || orderStore.load(-1L) == null) {
            throw new RuntimeException("Single delete operation test failed. Transaction wasn't committed yet, but " + "objects were already deleted from Cassandra");
        }
        tx.commit();
    } finally {
        U.closeQuiet(tx);
    }
    if (productStore.load(-1L) != null || orderStore.load(-1L) != null) {
        throw new RuntimeException("Single delete operation test failed. Transaction was committed, but " + "objects were not deleted from Cassandra");
    }
    LOGGER.info("Single delete tests passed");
    LOGGER.info("Running bulk delete tests");
    tx = txs.txStart(concurrency, isolation);
    try {
        productCache.removeAll(productsMap.keySet());
        orderCache.removeAll(ordersMap.keySet());
        productsMap1 = (Map<Long, Product>) productStore.loadAll(productsMap.keySet());
        ordersMap1 = (Map<Long, ProductOrder>) orderStore.loadAll(ordersMap.keySet());
        if (productsMap1.size() != productsMap.size() || ordersMap1.size() != ordersMap.size()) {
            throw new RuntimeException("Bulk delete operation test failed. Transaction wasn't committed yet, but " + "objects were already deleted from Cassandra");
        }
        tx.commit();
    } finally {
        U.closeQuiet(tx);
    }
    productsMap1 = (Map<Long, Product>) productStore.loadAll(productsMap.keySet());
    ordersMap1 = (Map<Long, ProductOrder>) orderStore.loadAll(ordersMap.keySet());
    if ((productsMap1 != null && !productsMap1.isEmpty()) || (ordersMap1 != null && !ordersMap1.isEmpty())) {
        throw new RuntimeException("Bulk delete operation test failed. Transaction was committed, but " + "objects were not deleted from Cassandra");
    }
    LOGGER.info("Bulk delete tests passed");
    LOGGER.info("POJO strategy delete tests passed");
    LOGGER.info("-----------------------------------------------------------------------------------");
    LOGGER.info("Passed POJO transaction tests for " + concurrency + " concurrency and " + isolation + " isolation level");
    LOGGER.info("-----------------------------------------------------------------------------------");
}
Also used : Product(org.apache.ignite.tests.pojos.Product) IgniteTransactions(org.apache.ignite.IgniteTransactions) ClassPathResource(org.springframework.core.io.ClassPathResource) Date(java.util.Date) Transaction(org.apache.ignite.transactions.Transaction) CacheStore(org.apache.ignite.cache.store.CacheStore) Map(java.util.Map) ProductOrder(org.apache.ignite.tests.pojos.ProductOrder)

Example 15 with CacheStore

use of org.apache.ignite.cache.store.CacheStore in project ignite by apache.

the class IgnitePersistentStoreTest method loadCacheTest.

/** */
@Test
public void loadCacheTest() {
    Ignition.stopAll(true);
    LOGGER.info("Running loadCache test");
    LOGGER.info("Filling Cassandra table with test data");
    CacheStore store = CacheStoreHelper.createCacheStore("personTypes", new ClassPathResource("org/apache/ignite/tests/persistence/pojo/persistence-settings-3.xml"), CassandraHelper.getAdminDataSrc());
    Collection<CacheEntryImpl<PersonId, Person>> entries = TestsHelper.generatePersonIdsPersonsEntries();
    //noinspection unchecked
    store.writeAll(entries);
    LOGGER.info("Cassandra table filled with test data");
    LOGGER.info("Running loadCache test");
    try (Ignite ignite = Ignition.start("org/apache/ignite/tests/persistence/pojo/ignite-config.xml")) {
        CacheConfiguration<PersonId, Person> ccfg = new CacheConfiguration<>("cache3");
        IgniteCache<PersonId, Person> personCache3 = ignite.getOrCreateCache(ccfg);
        int size = personCache3.size(CachePeekMode.ALL);
        LOGGER.info("Initial cache size " + size);
        LOGGER.info("Loading cache data from Cassandra table");
        String qry = "select * from test1.pojo_test3 limit 3";
        personCache3.loadCache(null, qry);
        size = personCache3.size(CachePeekMode.ALL);
        Assert.assertEquals("Cache data was incorrectly loaded from Cassandra table by '" + qry + "'", 3, size);
        personCache3.clear();
        personCache3.loadCache(null, new SimpleStatement(qry));
        size = personCache3.size(CachePeekMode.ALL);
        Assert.assertEquals("Cache data was incorrectly loaded from Cassandra table by statement", 3, size);
        personCache3.clear();
        personCache3.loadCache(null);
        size = personCache3.size(CachePeekMode.ALL);
        Assert.assertEquals("Cache data was incorrectly loaded from Cassandra. " + "Expected number of records is " + TestsHelper.getBulkOperationSize() + ", but loaded number of records is " + size, TestsHelper.getBulkOperationSize(), size);
        LOGGER.info("Cache data loaded from Cassandra table");
    }
    LOGGER.info("loadCache test passed");
}
Also used : SimpleStatement(com.datastax.driver.core.SimpleStatement) ClassPathResource(org.springframework.core.io.ClassPathResource) CacheEntryImpl(org.apache.ignite.internal.processors.cache.CacheEntryImpl) PersonId(org.apache.ignite.tests.pojos.PersonId) Ignite(org.apache.ignite.Ignite) CacheStore(org.apache.ignite.cache.store.CacheStore) Person(org.apache.ignite.tests.pojos.Person) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Test(org.junit.Test)

Aggregations

CacheStore (org.apache.ignite.cache.store.CacheStore)22 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)11 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)7 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)6 ClassPathResource (org.springframework.core.io.ClassPathResource)6 Map (java.util.Map)5 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)5 CacheEntryImpl (org.apache.ignite.internal.processors.cache.CacheEntryImpl)5 Test (org.junit.Test)5 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)3 Person (org.apache.ignite.tests.pojos.Person)3 Product (org.apache.ignite.tests.pojos.Product)3 ProductOrder (org.apache.ignite.tests.pojos.ProductOrder)3 Ignite (org.apache.ignite.Ignite)2 GridCacheTestStore (org.apache.ignite.internal.processors.cache.GridCacheTestStore)2 Transaction (org.apache.ignite.transactions.Transaction)2 SimpleStatement (com.datastax.driver.core.SimpleStatement)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1