Move the Guava JCache provider into the test targets only, don't assume a CacheManager instance exists.
This commit is contained in:
parent
d69d8a3b1e
commit
76b603f3d3
8 changed files with 330 additions and 181 deletions
|
@ -36,7 +36,6 @@
|
|||
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: javax.cache:cache-api:1.1.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.google.guava:guava:20.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: ca.exprofesso:guava-jcache:1.0.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.zipkin.java:zipkin:1.29.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.zipkin.brave:brave:4.0.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.zipkin.reporter:zipkin-reporter:0.6.12" level="project" />
|
||||
|
@ -118,6 +117,7 @@
|
|||
<orderEntry type="library" scope="TEST" name="Maven: org.caffinitas.ohc:ohc-core:0.4.4" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: com.github.ben-manes.caffeine:caffeine:2.2.6" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.jctools:jctools-core:1.2.1" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: ca.exprofesso:guava-jcache:1.0.4" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: commons-io:commons-io:2.5" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-library:1.3" level="project" />
|
||||
|
|
34
pom.xml
34
pom.xml
|
@ -154,22 +154,6 @@
|
|||
<version>20.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>ca.exprofesso</groupId>
|
||||
<artifactId>guava-jcache</artifactId>
|
||||
<version>1.0.4</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>javax.cache</groupId>
|
||||
<artifactId>cache-api</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- Metrics and tracing -->
|
||||
<dependency>
|
||||
<groupId>io.zipkin.java</groupId>
|
||||
|
@ -239,6 +223,24 @@
|
|||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>ca.exprofesso</groupId>
|
||||
<artifactId>guava-jcache</artifactId>
|
||||
<version>1.0.4</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>javax.cache</groupId>
|
||||
<artifactId>cache-api</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
|
|
|
@ -28,10 +28,8 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.cache.Cache;
|
||||
import javax.cache.CacheManager;
|
||||
|
||||
import net.helenus.core.cache.CacheUtil;
|
||||
import net.helenus.core.cache.Facet;
|
||||
import net.helenus.core.operation.AbstractOperation;
|
||||
|
|
|
@ -15,11 +15,24 @@
|
|||
*/
|
||||
package net.helenus.core;
|
||||
|
||||
import static net.helenus.core.Query.eq;
|
||||
|
||||
import brave.Tracer;
|
||||
import ca.exprofesso.guava.jcache.GuavaCachingProvider;
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import com.datastax.driver.core.*;
|
||||
import com.google.common.collect.Table;
|
||||
import java.io.Closeable;
|
||||
import java.io.PrintStream;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.cache.Cache;
|
||||
import javax.cache.CacheManager;
|
||||
import net.helenus.core.cache.CacheUtil;
|
||||
import net.helenus.core.cache.Facet;
|
||||
import net.helenus.core.cache.UnboundFacet;
|
||||
|
@ -38,23 +51,6 @@ import net.helenus.support.Fun.Tuple6;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.cache.Cache;
|
||||
import javax.cache.CacheManager;
|
||||
import javax.cache.Caching;
|
||||
import javax.cache.spi.CachingProvider;
|
||||
import java.io.Closeable;
|
||||
import java.io.PrintStream;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static net.helenus.core.Query.eq;
|
||||
|
||||
public class HelenusSession extends AbstractSessionOperations implements Closeable {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(HelenusSession.class);
|
||||
|
@ -114,13 +110,7 @@ public class HelenusSession extends AbstractSessionOperations implements Closeab
|
|||
this.unitOfWorkClass = unitOfWorkClass;
|
||||
this.metricRegistry = metricRegistry;
|
||||
this.zipkinTracer = tracer;
|
||||
|
||||
if (cacheManager == null) {
|
||||
CachingProvider cachingProvider = Caching.getCachingProvider(GuavaCachingProvider.class.getName());
|
||||
this.cacheManager = cachingProvider.getCacheManager();
|
||||
} else {
|
||||
this.cacheManager = cacheManager;
|
||||
}
|
||||
|
||||
this.valueProvider = new RowColumnValueProvider(this.sessionRepository);
|
||||
this.valuePreparer = new StatementColumnValuePreparer(this.sessionRepository);
|
||||
|
@ -220,6 +210,7 @@ public class HelenusSession extends AbstractSessionOperations implements Closeab
|
|||
@Override
|
||||
public Object checkCache(String tableName, List<Facet> facets) {
|
||||
Object result = null;
|
||||
if (cacheManager != null) {
|
||||
Cache<String, Object> cache = cacheManager.getCache(tableName);
|
||||
if (cache != null) {
|
||||
for (String key : CacheUtil.flatKeys(tableName, facets)) {
|
||||
|
@ -229,17 +220,20 @@ public class HelenusSession extends AbstractSessionOperations implements Closeab
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cacheEvict(List<Facet> facets) {
|
||||
if (cacheManager != null) {
|
||||
String tableName = CacheUtil.schemaName(facets);
|
||||
Cache<String, Object> cache = cacheManager.getCache(tableName);
|
||||
if (cache != null) {
|
||||
CacheUtil.flatKeys(tableName, facets).forEach(key -> cache.remove(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCache(Object pojo, List<Facet> facets) {
|
||||
|
@ -276,9 +270,7 @@ public class HelenusSession extends AbstractSessionOperations implements Closeab
|
|||
|
||||
@Override
|
||||
public void mergeCache(Table<String, String, Either<Object, List<Facet>>> uowCache) {
|
||||
if (cacheManager == null) {
|
||||
return;
|
||||
}
|
||||
if (cacheManager != null) {
|
||||
List<Object> items =
|
||||
uowCache
|
||||
.values()
|
||||
|
@ -325,7 +317,6 @@ public class HelenusSession extends AbstractSessionOperations implements Closeab
|
|||
}
|
||||
}
|
||||
|
||||
if (cacheManager != null) {
|
||||
List<List<Facet>> deletedFacetSets =
|
||||
uowCache
|
||||
.values()
|
||||
|
@ -346,9 +337,9 @@ public class HelenusSession extends AbstractSessionOperations implements Closeab
|
|||
|
||||
private void replaceCachedFacetValues(
|
||||
Object pojo, String tableName, List<String[]> facetCombinations) {
|
||||
if (cacheManager != null) {
|
||||
for (String[] combination : facetCombinations) {
|
||||
String cacheKey = tableName + "." + Arrays.toString(combination);
|
||||
if (cacheManager != null) {
|
||||
Cache<String, Object> cache = cacheManager.getCache(tableName);
|
||||
if (cache != null) {
|
||||
if (pojo == null || pojo == HelenusSession.deleted) {
|
||||
|
|
|
@ -19,6 +19,13 @@ import brave.Tracer;
|
|||
import com.codahale.metrics.MetricRegistry;
|
||||
import com.datastax.driver.core.*;
|
||||
import com.google.common.util.concurrent.MoreExecutors;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.function.Consumer;
|
||||
import javax.cache.CacheManager;
|
||||
import net.helenus.core.reflect.DslExportable;
|
||||
import net.helenus.mapping.HelenusEntity;
|
||||
import net.helenus.mapping.HelenusEntityType;
|
||||
|
@ -29,14 +36,6 @@ import net.helenus.support.Either;
|
|||
import net.helenus.support.HelenusException;
|
||||
import net.helenus.support.PackageUtil;
|
||||
|
||||
import javax.cache.CacheManager;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public final class SessionInitializer extends AbstractSessionOperations {
|
||||
|
||||
private final Session session;
|
||||
|
|
155
src/main/java/net/helenus/core/cache/MapCache.java
vendored
Normal file
155
src/main/java/net/helenus/core/cache/MapCache.java
vendored
Normal file
|
@ -0,0 +1,155 @@
|
|||
package net.helenus.core.cache;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.cache.Cache;
|
||||
import javax.cache.CacheManager;
|
||||
import javax.cache.configuration.CacheEntryListenerConfiguration;
|
||||
import javax.cache.configuration.Configuration;
|
||||
import javax.cache.integration.CompletionListener;
|
||||
import javax.cache.processor.EntryProcessor;
|
||||
import javax.cache.processor.EntryProcessorException;
|
||||
import javax.cache.processor.EntryProcessorResult;
|
||||
|
||||
public class MapCache<K, V> implements Cache<K, V> {
|
||||
|
||||
private Map<K, V> map = new HashMap<K, V>();
|
||||
|
||||
@Override
|
||||
public V get(K key) {
|
||||
return map.get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<K, V> getAll(Set<? extends K> keys) {
|
||||
Map<K, V> result = new HashMap<K, V>(keys.size());
|
||||
for (K key : keys) {
|
||||
V value = map.get(key);
|
||||
if (value != null) {
|
||||
result.put(key, value);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsKey(K key) {
|
||||
return map.containsKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadAll(
|
||||
Set<? extends K> keys,
|
||||
boolean replaceExistingValues,
|
||||
CompletionListener completionListener) {}
|
||||
|
||||
@Override
|
||||
public void put(K key, V value) {}
|
||||
|
||||
@Override
|
||||
public V getAndPut(K key, V value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putAll(Map<? extends K, ? extends V> map) {}
|
||||
|
||||
@Override
|
||||
public boolean putIfAbsent(K key, V value) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(K key) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(K key, V oldValue) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V getAndRemove(K key) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean replace(K key, V oldValue, V newValue) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean replace(K key, V value) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V getAndReplace(K key, V value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAll(Set<? extends K> keys) {}
|
||||
|
||||
@Override
|
||||
public void removeAll() {}
|
||||
|
||||
@Override
|
||||
public void clear() {}
|
||||
|
||||
@Override
|
||||
public <C extends Configuration<K, V>> C getConfiguration(Class<C> clazz) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T invoke(K key, EntryProcessor<K, V, T> entryProcessor, Object... arguments)
|
||||
throws EntryProcessorException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Map<K, EntryProcessorResult<T>> invokeAll(
|
||||
Set<? extends K> keys, EntryProcessor<K, V, T> entryProcessor, Object... arguments) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CacheManager getCacheManager() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {}
|
||||
|
||||
@Override
|
||||
public boolean isClosed() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T unwrap(Class<T> clazz) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerCacheEntryListener(
|
||||
CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration) {}
|
||||
|
||||
@Override
|
||||
public void deregisterCacheEntryListener(
|
||||
CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration) {}
|
||||
|
||||
@Override
|
||||
public Iterator<Entry<K, V>> iterator() {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -16,10 +16,10 @@
|
|||
package net.helenus.core.operation;
|
||||
|
||||
import com.codahale.metrics.Timer;
|
||||
import com.datastax.driver.core.AtomicMonotonicTimestampGenerator;
|
||||
import com.datastax.driver.core.BatchStatement;
|
||||
import com.datastax.driver.core.ResultSet;
|
||||
import com.datastax.driver.core.TimestampGenerator;
|
||||
import com.datastax.driver.core.AtomicMonotonicTimestampGenerator;
|
||||
import com.google.common.base.Stopwatch;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -31,7 +31,8 @@ import net.helenus.support.HelenusException;
|
|||
|
||||
public class BatchOperation extends Operation<Long> {
|
||||
//TODO(gburd): find the way to get the driver's timestamp generator
|
||||
private static final TimestampGenerator timestampGenerator = new AtomicMonotonicTimestampGenerator();
|
||||
private static final TimestampGenerator timestampGenerator =
|
||||
new AtomicMonotonicTimestampGenerator();
|
||||
|
||||
private final BatchStatement batch;
|
||||
private List<AbstractOperation<?, ?>> operations = new ArrayList<AbstractOperation<?, ?>>();
|
||||
|
|
|
@ -17,15 +17,16 @@ package net.helenus.test.integration.core.unitofwork;
|
|||
|
||||
import static net.helenus.core.Query.eq;
|
||||
|
||||
import ca.exprofesso.guava.jcache.GuavaCachingProvider;
|
||||
import com.datastax.driver.core.ConsistencyLevel;
|
||||
import com.datastax.driver.core.utils.UUIDs;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.cache.CacheManager;
|
||||
import javax.cache.Caching;
|
||||
import javax.cache.configuration.MutableConfiguration;
|
||||
|
||||
import javax.cache.spi.CachingProvider;
|
||||
import net.bytebuddy.utility.RandomString;
|
||||
import net.helenus.core.Helenus;
|
||||
import net.helenus.core.HelenusSession;
|
||||
|
@ -71,6 +72,14 @@ public class UnitOfWorkTest extends AbstractEmbeddedCassandraTest {
|
|||
|
||||
@BeforeClass
|
||||
public static void beforeTest() {
|
||||
CachingProvider cachingProvider =
|
||||
Caching.getCachingProvider(GuavaCachingProvider.class.getName());
|
||||
CacheManager cacheManager = cachingProvider.getCacheManager();
|
||||
MutableConfiguration<String, Object> configuration = new MutableConfiguration<>();
|
||||
configuration.setStoreByValue(false).setReadThrough(false);
|
||||
cacheManager.createCache(
|
||||
MappingUtil.getTableName(Widget.class, true).toString(), configuration);
|
||||
|
||||
session =
|
||||
Helenus.init(getSession())
|
||||
.showCql()
|
||||
|
@ -78,15 +87,9 @@ public class UnitOfWorkTest extends AbstractEmbeddedCassandraTest {
|
|||
.autoCreateDrop()
|
||||
.consistencyLevel(ConsistencyLevel.ONE)
|
||||
.idempotentQueryExecution(true)
|
||||
.setCacheManager(cacheManager)
|
||||
.get();
|
||||
widget = session.dsl(Widget.class);
|
||||
|
||||
MutableConfiguration<String, Object> configuration = new MutableConfiguration<>();
|
||||
configuration
|
||||
.setStoreByValue(false)
|
||||
.setReadThrough(false);
|
||||
CacheManager cacheManager = session.getCacheManager();
|
||||
cacheManager.createCache(MappingUtil.getTableName(Widget.class, true).toString(), configuration);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in a new issue