SGF-317 - Improved GemfireCache for Spring 4.1 compatibility.
Added putIfAbsent(…) to GemfireCache to make sure we can compile against Spring 4.1. Improved the implementation of get(Object, Class<T>) to adhere to the contract defined by the interface.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010 the original author or authors.
|
||||
* Copyright 2010-104 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,8 +16,14 @@
|
||||
|
||||
package org.springframework.data.gemfire.support;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.springframework.cache.Cache;
|
||||
|
||||
import com.gemstone.gemfire.cache.CacheFactory;
|
||||
@@ -27,18 +33,21 @@ import com.gemstone.gemfire.distributed.DistributedSystem;
|
||||
/**
|
||||
* @author Costin Leau
|
||||
* @author John Blum
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
// TODO avoid using actual GemFire Cache and Region instances, thereby creating a distributed system, for this test!
|
||||
// TODO Use Mocks!
|
||||
public class GemfireCacheTest extends AbstractNativeCacheTest<Region<Object, Object>> {
|
||||
|
||||
@Rule public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
@Override
|
||||
protected Cache createCache(Region<Object, Object> nativeCache) {
|
||||
return new GemfireCache(nativeCache);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"deprecation", "unchecked" })
|
||||
@SuppressWarnings({ "deprecation", "unchecked" })
|
||||
protected Region<Object, Object> createNativeCache() throws Exception {
|
||||
com.gemstone.gemfire.cache.Cache instance = null;
|
||||
|
||||
@@ -62,4 +71,43 @@ public class GemfireCacheTest extends AbstractNativeCacheTest<Region<Object, Obj
|
||||
return region;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see SGF-317
|
||||
*/
|
||||
@Test
|
||||
public void findsTypedValue() throws Exception {
|
||||
|
||||
GemfireCache cache = new GemfireCache(createNativeCache());
|
||||
cache.put("key", "value");
|
||||
|
||||
assertThat(cache.get("key", String.class), is("value"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see SGF-317
|
||||
*/
|
||||
@Test
|
||||
public void skipTypeChecksIfTargetTypeIsNull() throws Exception {
|
||||
|
||||
GemfireCache cache = new GemfireCache(createNativeCache());
|
||||
cache.put("key", "value");
|
||||
|
||||
assertThat(cache.get("key", null), is((Object) "value"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see SGF-317
|
||||
*/
|
||||
@Test
|
||||
public void throwsIllegalStateExceptionIfTypedAccessDoesntFindMatchingType() throws Exception {
|
||||
|
||||
GemfireCache cache = new GemfireCache(createNativeCache());
|
||||
cache.put("key", "value");
|
||||
|
||||
exception.expect(IllegalStateException.class);
|
||||
exception.expectMessage(Integer.class.getName());
|
||||
exception.expectMessage("value");
|
||||
|
||||
cache.get("key", Integer.class);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user