/hazelcast-spring/src/test/java/com/hazelcast/spring/cache/TestCacheManager.java
https://bitbucket.org/gabral6_gmailcom/hazelcast · Java · 96 lines · 65 code · 16 blank · 15 comment · 3 complexity · 58e6598f43a21e2316a7aff9331945be MD5 · raw file
- /*
- * Copyright (c) 2008-2013, Hazelcast, Inc. All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- package com.hazelcast.spring.cache;
- import com.hazelcast.core.Hazelcast;
- import com.hazelcast.core.HazelcastInstance;
- import com.hazelcast.impl.GroupProperties;
- import com.hazelcast.spring.CustomSpringJUnit4ClassRunner;
- import org.junit.AfterClass;
- import org.junit.Assert;
- import org.junit.BeforeClass;
- import org.junit.Test;
- import org.junit.runner.RunWith;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.cache.annotation.Cacheable;
- import org.springframework.test.context.ContextConfiguration;
- import javax.annotation.Resource;
- import java.util.concurrent.atomic.AtomicBoolean;
- @RunWith(CustomSpringJUnit4ClassRunner.class)
- @ContextConfiguration(locations = {"cacheManager-applicationContext-hazelcast.xml"})
- public class TestCacheManager {
- static {
- System.setProperty(GroupProperties.PROP_VERSION_CHECK_ENABLED, "false");
- }
- @Resource(name = "instance")
- private HazelcastInstance instance;
- @Autowired
- private IDummyBean bean;
- @BeforeClass
- @AfterClass
- public static void start() {
- Hazelcast.shutdownAll();
- }
- @Test
- public void test() {
- for (int i = 0; i < 100; i++) {
- Assert.assertEquals("name:" + i, bean.getName(i));
- Assert.assertEquals("city:" + i, bean.getCity(i));
- }
- }
- @Test
- public void testNull() {
- for (int i = 0; i < 100; i++) {
- Assert.assertNull(bean.getNull());
- }
- }
- public static class DummyBean implements IDummyBean {
- @Cacheable("name")
- public String getName(int k) {
- Assert.fail("should not call this method!");
- return null;
- }
- @Cacheable("city")
- public String getCity(int k) {
- Assert.fail("should not call this method!");
- return null;
- }
- final AtomicBoolean nullCall = new AtomicBoolean(false);
- @Cacheable("null-map")
- public Object getNull() {
- if (nullCall.compareAndSet(false, true)) {
- return null;
- }
- Assert.fail("should not call this method!");
- return null;
- }
- }
- }