1 package com.atlassian.vcache.internal.memcached;
2
3 import com.atlassian.vcache.ChangeRate;
4 import com.atlassian.vcache.VCacheFactory;
5 import com.atlassian.vcache.internal.RequestContext;
6 import com.atlassian.vcache.internal.VCacheLifecycleManager;
7 import com.atlassian.vcache.internal.VCacheManagement;
8 import com.atlassian.vcache.internal.core.DefaultVCacheCreationHandler;
9 import com.atlassian.vcache.internal.test.AbstractVCacheServiceIT;
10 import com.atlassian.vcache.internal.test.EmptyVCacheSettingsDefaultsProvider;
11 import com.atlassian.vcache.internal.test.ThreadLocalRequestContextSupplier;
12 import net.spy.memcached.AddrUtil;
13 import net.spy.memcached.BinaryConnectionFactory;
14 import net.spy.memcached.MemcachedClient;
15 import org.junit.After;
16 import org.junit.Before;
17 import org.junit.BeforeClass;
18
19 import java.io.IOException;
20
21 public class MemcachedVCacheServiceIT extends AbstractVCacheServiceIT {
22 private static MemcachedClient client;
23
24 private final ThreadLocalRequestContextSupplier requestContextSupplier =
25 ThreadLocalRequestContextSupplier.strictSupplier();
26
27 private MemcachedVCacheService service;
28
29 @Before
30 public void initService() {
31 final MemcachedVCacheServiceSettings settings = new MemcachedVCacheServiceSettingsBuilder()
32 .productIdentifier("confira")
33 .clientSupplier(() -> client)
34 .threadLocalContextSupplier(requestContextSupplier)
35 .workContextContextSupplier(requestContextSupplier)
36 .defaultsProvider(new EmptyVCacheSettingsDefaultsProvider())
37 .creationHandler(new DefaultVCacheCreationHandler(
38 MAX_ENTRIES,
39 MAX_TTL,
40 MAX_ENTRIES,
41 ChangeRate.HIGH_CHANGE,
42 ChangeRate.HIGH_CHANGE))
43 .begunTransactionalActivityHandler(begunTxnActivityHandler)
44 .build();
45 service = new MemcachedVCacheService(settings);
46 }
47
48 @Override
49 protected VCacheFactory vCacheFactory() {
50 return service;
51 }
52
53 @Override
54 protected VCacheManagement vCacheManagement() {
55 return service;
56 }
57
58 @Override
59 protected VCacheLifecycleManager vCacheLifecycleManager() {
60 return service;
61 }
62
63 @Override
64 protected RequestContext currentRequestContext() {
65 return requestContextSupplier.get();
66 }
67
68 @Override
69 protected void forceNewRequestContext() {
70 clearThread();
71 initThread();
72 }
73
74 @BeforeClass
75 public static void initClient() throws IOException {
76 client = new MemcachedClient(
77 new BinaryConnectionFactory(),
78 AddrUtil.getAddresses(System.getProperty("memcached.svr")));
79 }
80
81 @Before
82 public void initThread() {
83 requestContextSupplier.initThread("tenant-123");
84 }
85
86 @After
87 public void clearThread() {
88 requestContextSupplier.clearThread();
89 }
90 }