@Test
  public void removeRecordWithEntryProcessor() {
    final int ENTRY_COUNT = 10;

    CachingProvider cachingProvider = HazelcastServerCachingProvider.createCachingProvider(node1);
    CacheManager cacheManager = cachingProvider.getCacheManager();
    CompleteConfiguration<Integer, String> cacheConfig =
        new MutableConfiguration<Integer, String>().setTypes(Integer.class, String.class);
    ICache<Integer, String> cache =
        cacheManager.createCache("MyCache", cacheConfig).unwrap(ICache.class);

    for (int i = 0; i < ENTRY_COUNT; i++) {
      cache.put(i * 1000, "Value-" + (i * 1000));
    }

    assertEquals(ENTRY_COUNT, cache.size());

    for (int i = 0; i < ENTRY_COUNT; i++) {
      if (i % 2 == 0) {
        cache.invoke(i * 1000, new RemoveRecordEntryProcessor());
      }
    }

    assertEquals(ENTRY_COUNT / 2, cache.size());
  }
Beispiel #2
0
 private void populateLocalCacheEntrySet(ICache<K, T> cache) {
   cacheEntryList = new ConcurrentSkipListSet<>();
   Iterator<Cache.Entry<K, T>> cacheEntryIterator = cache.iterator();
   while (cacheEntryIterator.hasNext()) {
     cacheEntryList.add(cacheEntryIterator.next().getKey());
   }
   cacheConfig = cache.getConfiguration(CacheConfig.class);
   LOG.info("Populated local cache entry set with respect to remote cache provider.");
 }
Beispiel #3
0
 @Override
 public void close() {
   flush();
   cacheEntryList.clear();
   if (!cache.isDestroyed() && !manager.isClosed()) {
     cache.close();
   }
   if (!manager.isClosed()) {
     manager.close();
   }
   hazelcastInstance.shutdown();
   persistentDataStore.close();
   LOG.info("JCache Gora datastore destroyed successfully.");
 }
  @Setup
  public void setup(TestContext testContext) {
    HazelcastInstance hazelcastInstance = testContext.getTargetInstance();
    results = hazelcastInstance.getList(basename);
    listeners = hazelcastInstance.getList(basename + "listeners");

    cache = CacheUtils.getCache(hazelcastInstance, basename);
    listener = new ICacheEntryListener<Integer, Long>();
    filter = new ICacheEntryEventFilter<Integer, Long>();

    CacheEntryListenerConfiguration<Integer, Long> config =
        new MutableCacheEntryListenerConfiguration<Integer, Long>(
            FactoryBuilder.factoryOf(listener),
            FactoryBuilder.factoryOf(filter),
            false,
            syncEvents);
    cache.registerCacheEntryListener(config);

    builder
        .addOperation(Operation.PUT, put)
        .addOperation(Operation.PUT_EXPIRY, putExpiry)
        .addOperation(Operation.PUT_EXPIRY_ASYNC, putAsyncExpiry)
        .addOperation(Operation.GET_EXPIRY, getExpiry)
        .addOperation(Operation.GET_EXPIRY_ASYNC, getAsyncExpiry)
        .addOperation(Operation.REMOVE, remove)
        .addOperation(Operation.REPLACE, replace);
  }
 @Test
 public void testInvokeAllOperationSuccessfulWhenQuorumSizeMet() {
   HashSet<Integer> hashSet = new HashSet<Integer>();
   hashSet.add(123);
   EntryProcessorResult epr = cache1.invokeAll(hashSet, new SimpleEntryProcessor()).get(123);
   assertNull(epr);
 }
Beispiel #6
0
 @Override
 public T get(K key, String[] fields) {
   T persitent = (T) cache.get(key);
   if (persitent == null) {
     return null;
   }
   return getPersistent(persitent, fields);
 }
Beispiel #7
0
 @Override
 public void deleteSchema() {
   cache.removeAll();
   manager.destroyCache(super.getPersistentClass().getSimpleName());
   persistentDataStore.deleteSchema();
   LOG.info(
       "Deleted schema on persistent store and destroyed cache for persistent bean {}.",
       super.getPersistentClass().getSimpleName());
 }
  public static void main(String[] args) {
    init();

    try {
      ICache<Integer, Integer> cache = createCache("MyCacheForIteratorUsage");
      for (int i = 0; i < SIZE; i++) {
        cache.put(i, i * i);
      }

      Iterator<Cache.Entry<Integer, Integer>> iter = cache.iterator();
      while (iter.hasNext()) {
        Cache.Entry<Integer, Integer> e = iter.next();
        int key = e.getKey();
        int value = e.getValue();
        System.out.println("Key: " + key + ", Value: " + value);
      }

      cache.destroy();
    } catch (Throwable t) {
      t.printStackTrace();
    } finally {
      destroy();
    }
  }
Beispiel #9
0
 @Override
 public void createSchema() {
   if (manager.getCache(super.getPersistentClass().getSimpleName(), keyClass, persistentClass)
       == null) {
     cacheEntryList.clear();
     cache =
         manager.createCache(persistentClass.getSimpleName(), cacheConfig).unwrap(ICache.class);
   }
   cache.registerCacheEntryListener(
       new MutableCacheEntryListenerConfiguration<>(
           JCacheCacheFactoryBuilder.factoryOfEntryListener(
               new JCacheCacheEntryListener<K, T>(cacheEntryList)),
           null,
           true,
           true));
   persistentDataStore.createSchema();
   LOG.info(
       "Created schema on persistent store and initialized cache for persistent bean {}.",
       super.getPersistentClass().getSimpleName());
 }
 @Test
 public void testGetAllOperationSuccessfulWhenQuorumSizeMet() {
   HashSet<Integer> hashSet = new HashSet<Integer>();
   hashSet.add(123);
   cache1.getAll(hashSet);
 }
 @Test(expected = QuorumException.class)
 public void testContainsOperationThrowsExceptionWhenQuorumSizeNotMet() {
   cache4.containsKey(1);
 }
 @Test
 public void testContainsOperationSuccessfulWhenQuorumSizeMet() {
   cache1.containsKey(1);
 }
 @Test(expected = QuorumException.class)
 public void testGetOperationThrowsExceptionWhenQuorumSizeNotMet() throws Exception {
   cache4.get(1);
 }
 @Test
 public void testGetOperationSuccessfulWhenQuorumSizeMet() throws Exception {
   cache1.get(1);
 }
 @Test
 public void testReplaceAsyncOperationSuccessfulWhenQuorumSizeMet() throws Exception {
   Future<Boolean> foo = cache1.replaceAsync(1, "");
   foo.get();
 }
 @Test(expected = QuorumException.class)
 public void testIteratorOperationThrowsExceptionWhenQuorumSizeNotMet() {
   cache4.iterator();
 }
 @Test(expected = EntryProcessorException.class)
 public void testInvokeAllOperationThrowsExceptionWhenQuorumSizeNotMet() {
   HashSet<Integer> hashSet = new HashSet<Integer>();
   hashSet.add(123);
   cache4.invokeAll(hashSet, new SimpleEntryProcessor()).get(123).get();
 }
 @Test
 public void testInvokeOperationSuccessfulWhenQuorumSizeMet() {
   cache1.invoke(123, new SimpleEntryProcessor());
 }
 @Test(expected = EntryProcessorException.class)
 public void testInvokeOperationThrowsExceptionWhenQuorumSizeNotMet() {
   cache4.invoke(123, new SimpleEntryProcessor());
 }
 @Test(expected = QuorumException.class)
 public void testDestroyOperationThrowsExceptionWhenQuorumSizeNotMet() {
   cache4.destroy();
 }
 @Test
 public void testDestroyOperationSuccessfulWhenQuorumSizeMet() {
   cache1.destroy();
 }
 @Test(expected = ExecutionException.class)
 public void testReplaceAsyncOperationThrowsExceptionWhenQuorumSizeNotMet() throws Exception {
   Future<Boolean> foo = cache4.replaceAsync(1, "");
   foo.get();
 }
 @Test(expected = QuorumException.class)
 public void testGetAllOperationThrowsExceptionWhenQuorumSizeNotMet() {
   HashSet<Integer> hashSet = new HashSet<Integer>();
   hashSet.add(123);
   cache4.getAll(hashSet);
 }
 @Test(expected = ExecutionException.class)
 public void testGetAsyncOperationThrowsExceptionWhenQuorumSizeNotMet() throws Exception {
   Future<String> foo = cache4.getAsync(1);
   foo.get();
 }
 @Test
 public void testIteratorOperationSuccessfulWhenQuorumSizeMet() {
   cache1.iterator();
 }
 @Test
 public void testPutAsyncOperationSuccessfulWhenQuorumSizeMet() throws Exception {
   Future<Void> foo = cache1.putAsync(1, "");
   foo.get();
 }
 @Test
 public void testGetAsyncOperationSuccessfulWhenQuorumSizeMet() throws Exception {
   Future<String> foo = cache1.getAsync(1);
   foo.get();
 }
 @Test(expected = ExecutionException.class)
 public void testPutAsyncOperationThrowsExceptionWhenQuorumSizeNotMet() throws Exception {
   Future<Void> foo = cache4.putAsync(1, "");
   foo.get();
 }
 @Test
 public void testPutGetWhenQuorumSizeMet() {
   cache1.put(123, "foo");
   assertEquals("foo", cache2.get(123));
 }
 @Test
 public void testPutRemoveGetShouldReturnNullWhenQuorumSizeMet() {
   cache1.put(123, "foo");
   cache1.remove(123);
   assertNull(cache2.get(123));
 }