Package javax.cache

Examples of javax.cache.CacheManager


    }

    @Test
    public void testIterator() {

        CacheManager cacheManager = cachingProvider1.getCacheManager();

        CacheConfig<Integer, String> config = new CacheConfig<Integer, String>();
        config.setName("SimpleCache");

        ICache<Integer, String> cache = (ICache<Integer, String>) cacheManager.createCache("simpleCache", config);

        int testSize = 1007;
        for (int i = 0; i < testSize; i++) {
            Integer key = i;
            String value1 = "value" + i;
View Full Code Here


        }
    }

    @Test
    public void testCachesTypedConfig() {
        CacheManager cacheManager = cachingProvider1.getCacheManager();

        CacheConfig<Integer, Long> config = new CacheConfig();
        String cacheName = "test";
        config.setName(cacheName);
        config.setTypes(Integer.class, Long.class);

        Cache<Integer, Long> cache = cacheManager.createCache(cacheName, config);
        Cache<Integer, Long> cache2 = cacheManager.getCache(cacheName, config.getKeyType(), config.getValueType());

        assertNotNull(cache);
        assertNotNull(cache2);
    }
View Full Code Here

    }

    @Test
    public void testSyncListener() throws Exception {
        CachingProvider cachingProvider = getCachingProvider();
        CacheManager cacheManager = cachingProvider.getCacheManager();

        final AtomicInteger counter = new AtomicInteger();

        CompleteConfiguration<String, String> config = new MutableConfiguration<String, String>()
                .setTypes(String.class, String.class).addCacheEntryListenerConfiguration(
                        new MutableCacheEntryListenerConfiguration<String, String>(
                                FactoryBuilder.factoryOf(new TestListener(counter)), null, true, true));

        final Cache<String, String> cache = cacheManager.createCache("test", config);

        final int threadCount = 10;
        final int putCount = 1000;
        final CountDownLatch latch = new CountDownLatch(threadCount);
        for (int i = 0; i < threadCount; i++) {
View Full Code Here

//        HazelcastCacheManager cacheManager = new HazelcastCacheManager(hcp,instance,hcp.getDefaultURI(),hcp.getDefaultClassLoader(),null);

        final CachingProvider cachingProvider = HazelcastServerCachingProvider.createCachingProvider(instance);
//        final CachingProvider cachingProvider = Caching.getCachingProvider();

        final CacheManager cacheManager = cachingProvider.getCacheManager();


        CacheConfig<String, Object> config = new CacheConfig<String, Object>();
        config.setTypes(String.class, Object.class);
        config.setStatisticsEnabled(true);

        cacheManager.createCache(NAMESPACE, config);

//        final IMap<String, Object> map = instance.getMap(NAMESPACE);
        for (int i = 0; i < threadCount; i++) {
            es.execute(new Runnable() {
                public void run() {
                    try {
                        while (true) {
                            final Cache<String, Object> cache = cacheManager.getCache(NAMESPACE,String.class, Object.class);
                            int key = (int) (random.nextFloat() * entryCount);
                            int operation = ((int) (random.nextFloat() * 100));
                            if (operation < getPercentage) {
                                cache.get(String.valueOf(key));
                                stats.gets.incrementAndGet();
View Full Code Here

    }

    @Test
    public void test_execution_entryprocessor_default_backup() throws Exception {
        CachingProvider cachingProvider = HazelcastServerCachingProvider.createCachingProvider(hz1);
        CacheManager cacheManager = cachingProvider.getCacheManager();

        String cacheName = randomString();

        CompleteConfiguration<Integer, String> config =
                new MutableConfiguration<Integer, String>()
                        .setTypes(Integer.class, String.class);

        Cache<Integer, String> cache = cacheManager.createCache(cacheName, config);

        cache.invoke(1, new SimpleEntryProcessor());

        final Data key = serializationService.toData(1);
        final int partitionId = hz1.getPartitionService().getPartition(1).getPartitionId();
View Full Code Here

    }

    @Test
    public void test_execution_entryprocessor_with_backup_entry_processor() throws Exception {
        CachingProvider cachingProvider = HazelcastServerCachingProvider.createCachingProvider(hz1);
        CacheManager cacheManager = cachingProvider.getCacheManager();

        String cacheName = randomString();

        CompleteConfiguration<Integer, String> config =
                new MutableConfiguration<Integer, String>()
                        .setTypes(Integer.class, String.class);

        Cache<Integer, String> cache = cacheManager.createCache(cacheName, config);

        cache.invoke(1, new SimpleBackupAwareEntryProcessor());

        final Data key = serializationService.toData(1);
        final int partitionId = hz1.getPartitionService().getPartition(1).getPartitionId();
View Full Code Here

    }

    @Test
    public void test_execution_entryprocessor_with_backup_entry_processor_null() throws Exception {
        CachingProvider cachingProvider = HazelcastServerCachingProvider.createCachingProvider(hz1);
        CacheManager cacheManager = cachingProvider.getCacheManager();

        String cacheName = randomString();

        CompleteConfiguration<Integer, String> config =
                new MutableConfiguration<Integer, String>()
                        .setTypes(Integer.class, String.class);

        Cache<Integer, String> cache = cacheManager.createCache(cacheName, config);

        cache.invoke(1, new NullBackupAwareEntryProcessor());

        final Data key = serializationService.toData(1);
        final int partitionId = hz1.getPartitionService().getPartition(1).getPartitionId();
View Full Code Here

    }

    @Test
    public void test_execution_entryprocessor_with_backup_entry_processor_custom_backup() throws Exception {
        CachingProvider cachingProvider = HazelcastServerCachingProvider.createCachingProvider(hz1);
        CacheManager cacheManager = cachingProvider.getCacheManager();

        String cacheName = randomString();

        CompleteConfiguration<Integer, String> config =
                new MutableConfiguration<Integer, String>()
                        .setTypes(Integer.class, String.class);

        Cache<Integer, String> cache = cacheManager.createCache(cacheName, config);

        cache.invoke(1, new CustomBackupAwareEntryProcessor());

        final Data key = serializationService.toData(1);
        final int partitionId = hz1.getPartitionService().getPartition(1).getPartitionId();
View Full Code Here

    public void cacheManagerByLocationClasspathTest()
            throws URISyntaxException {
        URI uri1 = new URI("MY-SCOPE");
        Properties properties = new Properties();
        properties.setProperty(HazelcastCachingProvider.HAZELCAST_CONFIG_LOCATION, "classpath:test-hazelcast-jcache.xml");
        CacheManager cacheManager = Caching.getCachingProvider().getCacheManager(uri1, null, properties);
        assertNotNull(cacheManager);

        Cache<Integer, String> testCache = cacheManager.getCache("testCache", Integer.class, String.class);
        assertNotNull(testCache);

        Caching.getCachingProvider().close();
    }
View Full Code Here

        String urlStr = configUrl1.toString();
        assertEquals("file", urlStr.substring(0,4));
        Properties properties = new Properties();
        properties.setProperty(HazelcastCachingProvider.HAZELCAST_CONFIG_LOCATION, urlStr);
        CacheManager cacheManager = Caching.getCachingProvider().getCacheManager(uri, null, properties);
        assertNotNull(cacheManager);

        URI uri2 = new URI("MY-SCOPE-OTHER");
        String urlStr2 = configUrl2.toString();
        assertEquals("file", urlStr2.substring(0,4));
        Properties properties2 = new Properties();
        properties2.setProperty(HazelcastCachingProvider.HAZELCAST_CONFIG_LOCATION, urlStr2);
        CacheManager cacheManager2 = Caching.getCachingProvider().getCacheManager(uri2, null, properties2);
        assertNotNull(cacheManager2);

        assertEquals(2, Hazelcast.getAllHazelcastInstances().size() );
        Caching.getCachingProvider().close();
    }
View Full Code Here

TOP

Related Classes of javax.cache.CacheManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.