Created
June 23, 2012 14:22
-
-
Save umit/2978447 to your computer and use it in GitHub Desktop.
HazelcastInstanceTest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.umitunal.hazelcast; | |
import static org.junit.Assert.*; | |
import javax.annotation.Resource; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.springframework.test.context.ContextConfiguration; | |
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | |
import com.hazelcast.core.Hazelcast; | |
import com.hazelcast.core.HazelcastInstance; | |
import com.hazelcast.core.IMap; | |
@RunWith(SpringJUnit4ClassRunner.class) | |
@ContextConfiguration(locations = {"classpath:applicationContext-Hazelcast.xml"}) | |
public class HazelcastInstanceTest { | |
@Resource(name = "instance") | |
private HazelcastInstance instance; | |
@Resource(name = "productMap") | |
private IMap<Object,Object> productMap; | |
@Test | |
public void testInstance() { | |
assertEquals(1, Hazelcast.getAllHazelcastInstances().size()); | |
} | |
@Test | |
public void testMap() { | |
assertNotNull(productMap); | |
productMap.put("key", "value"); | |
assertEquals(Boolean.TRUE, productMap.containsKey("key")); | |
assertEquals(Boolean.TRUE, productMap.containsValue("value")); | |
assertEquals(1, productMap.size()); | |
assertEquals("value", productMap.get("key")); | |
productMap.remove("key"); | |
assertEquals(Boolean.FALSE, productMap.containsKey("key")); | |
assertEquals(Boolean.FALSE, productMap.containsValue("value")); | |
assertEquals(0, productMap.size()); | |
assertNull(productMap.get("key")); | |
} | |
@Test | |
public void testMapWithInstance() { | |
IMap<Object,Object> productMap = instance.getMap("productMap"); | |
productMap.put("key", "value"); | |
assertEquals(Boolean.TRUE, productMap.containsKey("key")); | |
assertEquals(Boolean.TRUE, productMap.containsValue("value")); | |
assertEquals(1, productMap.size()); | |
assertEquals("value", productMap.get("key")); | |
productMap.remove("key"); | |
assertEquals(Boolean.FALSE, productMap.containsKey("key")); | |
assertEquals(Boolean.FALSE, productMap.containsValue("value")); | |
assertEquals(0, productMap.size()); | |
assertNull(productMap.get("key")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment