1 package com.atlassian.vcache.internal.legacy;
2
3 import com.atlassian.cache.CacheFactory;
4 import com.atlassian.cache.CacheSettings;
5 import com.atlassian.cache.CacheSettingsBuilder;
6 import com.atlassian.cache.ehcache.EhCacheManager;
7 import com.atlassian.cache.ehcache.replication.rmi.RMICacheReplicatorConfigFactory;
8 import com.atlassian.marshalling.jdk.StringMarshalling;
9 import com.atlassian.vcache.DirectExternalCache;
10 import com.atlassian.vcache.ExternalCacheSettings;
11 import com.atlassian.vcache.internal.RequestContext;
12 import com.atlassian.vcache.internal.RequestMetrics;
13 import com.atlassian.vcache.internal.core.DefaultRequestContext;
14 import com.atlassian.vcache.internal.core.Sha1ExternalCacheKeyGenerator;
15 import com.atlassian.vcache.internal.core.metrics.DefaultMetricsCollector;
16 import com.atlassian.vcache.internal.core.metrics.MetricsCollector;
17 import com.atlassian.vcache.internal.test.AbstractDirectExternalCacheIT;
18 import net.sf.ehcache.CacheManager;
19 import org.junit.Ignore;
20
21 import java.util.Optional;
22 import java.util.concurrent.ExecutionException;
23 import java.util.concurrent.TimeUnit;
24
25 public class LegacyDirectExternalCacheEhcacheIT extends AbstractDirectExternalCacheIT {
26 private final RequestContext requestContext = new DefaultRequestContext("tenant-id");
27 private final MetricsCollector metricsCollector = new DefaultMetricsCollector(() -> requestContext);
28 private CacheFactory cacheFactory;
29 {
30 final CacheManager rawEhcache = CacheManager.create();
31
32 rawEhcache.removeAllCaches();
33
34 cacheFactory = new EhCacheManager(rawEhcache, new RMICacheReplicatorConfigFactory(), null);
35 }
36
37 @Override
38 protected DirectExternalCache<String> createCache(String name, ExternalCacheSettings settings) {
39 final CacheSettings legacySettings = new CacheSettingsBuilder()
40 .remote()
41 .maxEntries(settings.getEntryCountHint().get())
42 .expireAfterWrite(settings.getDefaultTtl().get().toNanos(), TimeUnit.NANOSECONDS)
43 .build();
44
45 return metricsCollector.wrap(
46 new LegacyDirectExternalCache<>(
47 cacheFactory.getCache(name, null, legacySettings),
48 () -> requestContext,
49 new Sha1ExternalCacheKeyGenerator("it-test-42"),
50 Optional.of(StringMarshalling.pair()),
51 new LegacyServiceSettingsBuilder().enableAvoidCasOperations().build()));
52 }
53
54 @Override
55 protected RequestMetrics requestMetrics() {
56 return metricsCollector.obtainRequestMetrics(requestContext);
57 }
58
59 @Ignore("CAS operations not supported")
60 @Override
61 public void simple_get_add() throws ExecutionException, InterruptedException {
62 }
63
64 @Ignore("CAS operations not supported")
65 @Override
66 public void simple_getBulkIdentified() throws ExecutionException, InterruptedException {
67 }
68
69 @Ignore("CAS operations not supported")
70 @Override
71 public void simple_getIdentified_removeIf() throws ExecutionException, InterruptedException {
72 }
73
74 @Ignore("CAS operations not supported")
75 @Override
76 public void simple_getIdentifiedSupplier_removeIf() throws ExecutionException, InterruptedException {
77 }
78
79 @Ignore("CAS operations not supported")
80 @Override
81 public void exact_getIdentified_removeIf() throws ExecutionException, InterruptedException {
82 }
83
84 @Ignore("CAS operations not supported")
85 @Override
86 public void simple_getIdentified_replaceIf() throws ExecutionException, InterruptedException {
87 }
88
89 @Ignore("CAS operations not supported")
90 @Override
91 public void exact_getIdentified_replaceIf() throws ExecutionException, InterruptedException {
92 }
93
94 @Ignore("CAS operations not supported")
95 @Override
96 public void check_null_detection_with_cas() {
97 }
98 }