Search in sources :

Example 1 with GridCacheInternalKeyImpl

use of org.apache.ignite.internal.processors.datastructures.GridCacheInternalKeyImpl in project ignite by apache.

the class IgniteCacheAbstractFieldsQuerySelfTest method testCacheMetaData.

/** @throws Exception If failed. */
public void testCacheMetaData() throws Exception {
    for (String cacheName : grid(0).cacheNames()) ((IgniteKernal) grid(0)).getCache(cacheName).getAndPut(new GridCacheInternalKeyImpl("LONG"), new GridCacheAtomicLongValue(0));
    try {
        Collection<GridCacheSqlMetadata> metas = ((IgniteKernal) grid(0)).getCache(intCache.getName()).context().queries().sqlMetadata();
        assert metas != null;
        for (GridCacheSqlMetadata meta : metas) {
            Collection<String> types = meta.types();
            assertNotNull(types);
            if (personCache.getName().equals(meta.cacheName())) {
                assertEquals("Invalid types size", 1, types.size());
                assert types.contains("Person");
                if (binaryMarshaller) {
                    assert Object.class.getName().equals(meta.keyClass("Person"));
                    assert Object.class.getName().equals(meta.valueClass("Person"));
                } else {
                    assert AffinityKey.class.getName().equals(meta.keyClass("Person"));
                    assert Person.class.getName().equals(meta.valueClass("Person"));
                }
                Map<String, String> fields = meta.fields("Person");
                assert fields != null;
                assert fields.size() == 3;
                if (binaryMarshaller) {
                    assert Integer.class.getName().equals(fields.get("AGE"));
                    assert Integer.class.getName().equals(fields.get("ORGID"));
                } else {
                    assert int.class.getName().equals(fields.get("AGE"));
                    assert int.class.getName().equals(fields.get("ORGID"));
                }
                assert String.class.getName().equals(fields.get("NAME"));
                Collection<GridCacheSqlIndexMetadata> indexes = meta.indexes("Person");
                assertNotNull("Indexes should be defined", indexes);
                assertEquals(2, indexes.size());
                Set<String> idxFields = new HashSet<>();
                Iterator<GridCacheSqlIndexMetadata> it = indexes.iterator();
                Collection<String> indFlds = it.next().fields();
                assertNotNull("Fields for first index should be defined", indFlds);
                assertEquals("First index should have one field", indFlds.size(), 1);
                Iterator<String> indFldIt = indFlds.iterator();
                idxFields.add(indFldIt.next());
                indFlds = it.next().fields();
                assertNotNull("Fields for second index should be defined", indFlds);
                assertEquals("Second index should have one field", indFlds.size(), 1);
                indFldIt = indFlds.iterator();
                idxFields.add(indFldIt.next());
                assertTrue(idxFields.contains("AGE"));
                assertTrue(idxFields.contains("ORGID"));
            } else if (orgCache.getName().equals(meta.cacheName())) {
                assertEquals("Invalid types size", 1, types.size());
                assert types.contains("Organization");
                if (binaryMarshaller)
                    assert Object.class.getName().equals(meta.valueClass("Organization"));
                else
                    assert Organization.class.getName().equals(meta.valueClass("Organization"));
                assert String.class.getName().equals(meta.keyClass("Organization"));
                Map<String, String> fields = meta.fields("Organization");
                assert fields != null;
                assertEquals("Fields: " + fields, 2, fields.size());
                if (binaryMarshaller) {
                    assert Integer.class.getName().equals(fields.get("ID"));
                } else {
                    assert int.class.getName().equals(fields.get("ID"));
                }
                assert String.class.getName().equals(fields.get("NAME"));
            } else if (intCache.getName().equals(meta.cacheName())) {
                assertEquals("Invalid types size", 1, types.size());
                assert types.contains("Integer");
                assert Integer.class.getName().equals(meta.valueClass("Integer"));
                assert Integer.class.getName().equals(meta.keyClass("Integer"));
                Map<String, String> fields = meta.fields("Integer");
                assert fields != null;
                assert fields.size() == 2;
                assert Integer.class.getName().equals(fields.get("_KEY"));
                assert Integer.class.getName().equals(fields.get("_VAL"));
            } else if (strCache.getName().equals(meta.cacheName())) {
                assertEquals("Invalid types size", 1, types.size());
                assert types.contains("String");
                assert String.class.getName().equals(meta.valueClass("String"));
                assert String.class.getName().equals(meta.keyClass("String"));
                Map<String, String> fields = meta.fields("String");
                assert fields != null;
                assert fields.size() == 2;
                assert String.class.getName().equals(fields.get("_KEY"));
                assert String.class.getName().equals(fields.get("_VAL"));
            } else if (DEFAULT_CACHE_NAME.equals(meta.cacheName()))
                assertTrue("Invalid types size", types.isEmpty());
            else
                fail("Unknown cache: " + meta.cacheName());
        }
    } finally {
        ((IgniteKernal) grid(0)).getCache(intCache.getName()).remove(new GridCacheInternalKeyImpl("LONG"));
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridCacheAtomicLongValue(org.apache.ignite.internal.processors.datastructures.GridCacheAtomicLongValue) GridCacheInternalKeyImpl(org.apache.ignite.internal.processors.datastructures.GridCacheInternalKeyImpl) GridCacheSqlIndexMetadata(org.apache.ignite.internal.processors.cache.query.GridCacheSqlIndexMetadata) GridCacheSqlMetadata(org.apache.ignite.internal.processors.cache.query.GridCacheSqlMetadata) Map(java.util.Map) AffinityKey(org.apache.ignite.cache.affinity.AffinityKey) HashSet(java.util.HashSet)

Example 2 with GridCacheInternalKeyImpl

use of org.apache.ignite.internal.processors.datastructures.GridCacheInternalKeyImpl in project ignite by apache.

the class GridCacheSequenceApiSelfAbstractTest method testCacheSets.

/**
     * @throws Exception If failed.
     */
public void testCacheSets() throws Exception {
    // Make new atomic sequence in cache.
    IgniteAtomicSequence seq = grid().atomicSequence(UUID.randomUUID().toString(), 0, true);
    seq.incrementAndGet();
    GridCacheAdapter cache = ((IgniteKernal) grid()).internalCache(GridCacheUtils.ATOMICS_CACHE_NAME);
    assertNotNull(cache);
    GridTestUtils.assertThrows(log, new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            grid().cache(GridCacheUtils.ATOMICS_CACHE_NAME);
            return null;
        }
    }, IllegalStateException.class, null);
    for (String seqName : seqNames) assert null != cache.get(new GridCacheInternalKeyImpl(seqName));
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) GridCacheInternalKeyImpl(org.apache.ignite.internal.processors.datastructures.GridCacheInternalKeyImpl) IgniteAtomicSequence(org.apache.ignite.IgniteAtomicSequence)

Example 3 with GridCacheInternalKeyImpl

use of org.apache.ignite.internal.processors.datastructures.GridCacheInternalKeyImpl in project ignite by apache.

the class GridCachePartitionedNodeRestartTxSelfTest method checkCustom.

/**
     * Test {@link GridCacheInternalKey}/{@link GridCacheAtomicLongValue}.
     * @param name Name.
     * @throws Exception If failed.
     */
private void checkCustom(String name) throws Exception {
    for (int i = INIT_GRID_NUM; i < 20; i++) {
        startGrid(i);
        assert PARTITIONED == grid(i).cache(DEFAULT_CACHE_NAME).getConfiguration(CacheConfiguration.class).getCacheMode();
        try (Transaction tx = grid(i).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
            GridCacheInternalKey key = new GridCacheInternalKeyImpl(name);
            GridCacheAtomicLongValue atomicVal = ((GridCacheAtomicLongValue) grid(i).cache(DEFAULT_CACHE_NAME).get(key));
            assertNotNull(atomicVal);
            assertEquals("Custom check failed for node: " + i, (long) i, atomicVal.get());
            atomicVal.set(i + 1);
            grid(i).cache(DEFAULT_CACHE_NAME).put(key, atomicVal);
            tx.commit();
        }
        stopGrid(i);
    }
}
Also used : Transaction(org.apache.ignite.transactions.Transaction) GridCacheAtomicLongValue(org.apache.ignite.internal.processors.datastructures.GridCacheAtomicLongValue) GridCacheInternalKeyImpl(org.apache.ignite.internal.processors.datastructures.GridCacheInternalKeyImpl) GridCacheInternalKey(org.apache.ignite.internal.processors.datastructures.GridCacheInternalKey)

Example 4 with GridCacheInternalKeyImpl

use of org.apache.ignite.internal.processors.datastructures.GridCacheInternalKeyImpl in project ignite by apache.

the class GridCacheContinuousQueryAbstractSelfTest method testInternalKey.

/**
     * @throws Exception If failed.
     */
public void testInternalKey() throws Exception {
    if (atomicityMode() == ATOMIC)
        return;
    IgniteCache<Object, Object> cache = grid(0).cache(DEFAULT_CACHE_NAME);
    ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
    final Map<Object, Object> map = new ConcurrentHashMap8<>();
    final CountDownLatch latch = new CountDownLatch(2);
    qry.setLocalListener(new CacheEntryUpdatedListener<Object, Object>() {

        @Override
        public void onUpdated(Iterable<CacheEntryEvent<?, ?>> evts) {
            for (CacheEntryEvent<?, ?> e : evts) {
                map.put(e.getKey(), e.getValue());
                latch.countDown();
            }
        }
    });
    try (QueryCursor<Cache.Entry<Object, Object>> ignored = cache.query(qry)) {
        cache.put(new GridCacheInternalKeyImpl("test"), 1);
        cache.put(1, 1);
        cache.put(2, 2);
        assert latch.await(LATCH_TIMEOUT, MILLISECONDS);
        assertEquals(2, map.size());
        assertEquals(1, (int) map.get(1));
        assertEquals(2, (int) map.get(2));
    }
}
Also used : GridCacheInternalKeyImpl(org.apache.ignite.internal.processors.datastructures.GridCacheInternalKeyImpl) ConcurrentHashMap8(org.jsr166.ConcurrentHashMap8) CountDownLatch(java.util.concurrent.CountDownLatch) CacheEntryEvent(javax.cache.event.CacheEntryEvent) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery)

Example 5 with GridCacheInternalKeyImpl

use of org.apache.ignite.internal.processors.datastructures.GridCacheInternalKeyImpl in project ignite by apache.

the class GridCachePartitionedNodeRestartTxSelfTest method prepareCustom.

/**
     * Prepare test environment.
     * @param key Key.
     * @throws Exception If failed.
     */
private void prepareCustom(String key) throws Exception {
    // Start nodes.
    for (int i = 0; i < INIT_GRID_NUM; i++) assert startGrid(i) != null;
    for (int i = 0; i < INIT_GRID_NUM; i++) assert PARTITIONED == grid(i).cache(DEFAULT_CACHE_NAME).getConfiguration(CacheConfiguration.class).getCacheMode();
    try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
        // Put custom data
        grid(0).cache(DEFAULT_CACHE_NAME).put(new GridCacheInternalKeyImpl(key), new GridCacheAtomicLongValue(INIT_GRID_NUM));
        tx.commit();
    }
    stopGrid(0);
}
Also used : Transaction(org.apache.ignite.transactions.Transaction) GridCacheAtomicLongValue(org.apache.ignite.internal.processors.datastructures.GridCacheAtomicLongValue) GridCacheInternalKeyImpl(org.apache.ignite.internal.processors.datastructures.GridCacheInternalKeyImpl) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Aggregations

GridCacheInternalKeyImpl (org.apache.ignite.internal.processors.datastructures.GridCacheInternalKeyImpl)5 GridCacheAtomicLongValue (org.apache.ignite.internal.processors.datastructures.GridCacheAtomicLongValue)3 IgniteKernal (org.apache.ignite.internal.IgniteKernal)2 Transaction (org.apache.ignite.transactions.Transaction)2 HashSet (java.util.HashSet)1 Map (java.util.Map)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 CacheEntryEvent (javax.cache.event.CacheEntryEvent)1 IgniteAtomicSequence (org.apache.ignite.IgniteAtomicSequence)1 AffinityKey (org.apache.ignite.cache.affinity.AffinityKey)1 ContinuousQuery (org.apache.ignite.cache.query.ContinuousQuery)1 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1 GridCacheAdapter (org.apache.ignite.internal.processors.cache.GridCacheAdapter)1 GridCacheSqlIndexMetadata (org.apache.ignite.internal.processors.cache.query.GridCacheSqlIndexMetadata)1 GridCacheSqlMetadata (org.apache.ignite.internal.processors.cache.query.GridCacheSqlMetadata)1 GridCacheInternalKey (org.apache.ignite.internal.processors.datastructures.GridCacheInternalKey)1 ConcurrentHashMap8 (org.jsr166.ConcurrentHashMap8)1