test
This commit is contained in:
@@ -40,6 +40,10 @@ public class CacheInstance implements Service {
|
|||||||
return "haha";
|
return "haha";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateName() {
|
||||||
|
cacheManager.bothSet("name", String.class, "gege", Duration.ofMillis(600), Duration.ofMillis(600));
|
||||||
|
}
|
||||||
|
|
||||||
@Cached(key = "name", localExpire = "30", remoteExpire = "60")
|
@Cached(key = "name", localExpire = "30", remoteExpire = "60")
|
||||||
public String getName2() throws RedkaleException {
|
public String getName2() throws RedkaleException {
|
||||||
return "haha";
|
return "haha";
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
package org.redkale.test.cache;
|
package org.redkale.test.cache;
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.redkale.cache.CacheManager;
|
import org.redkale.cache.CacheManager;
|
||||||
@@ -26,6 +27,10 @@ public class CacheInstanceTest {
|
|||||||
|
|
||||||
private static CacheManagerService manager;
|
private static CacheManagerService manager;
|
||||||
|
|
||||||
|
private static ResourceFactory resourceFactory2;
|
||||||
|
|
||||||
|
private static CacheManagerService manager2;
|
||||||
|
|
||||||
public static void main(String[] args) throws Throwable {
|
public static void main(String[] args) throws Throwable {
|
||||||
CacheInstanceTest test = new CacheInstanceTest();
|
CacheInstanceTest test = new CacheInstanceTest();
|
||||||
init();
|
init();
|
||||||
@@ -35,13 +40,20 @@ public class CacheInstanceTest {
|
|||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void init() throws Exception {
|
public static void init() throws Exception {
|
||||||
resourceFactory = ResourceFactory.create();
|
|
||||||
resourceFactory.register(new Environment());
|
|
||||||
CacheMemorySource remoteSource = new CacheMemorySource("cache-remote");
|
CacheMemorySource remoteSource = new CacheMemorySource("cache-remote");
|
||||||
remoteSource.init(null);
|
remoteSource.init(null);
|
||||||
|
resourceFactory = ResourceFactory.create();
|
||||||
|
resourceFactory.register(new Environment());
|
||||||
manager = CacheManagerService.create(remoteSource);
|
manager = CacheManagerService.create(remoteSource);
|
||||||
manager.init(null);
|
manager.init(null);
|
||||||
resourceFactory.register("", CacheManager.class, manager);
|
resourceFactory.register("", CacheManager.class, manager);
|
||||||
|
|
||||||
|
resourceFactory2 = ResourceFactory.create();
|
||||||
|
resourceFactory2.register(new Environment());
|
||||||
|
manager2 = CacheManagerService.create(remoteSource);
|
||||||
|
manager2.init(null);
|
||||||
|
resourceFactory2.register("", CacheManager.class, manager2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -54,7 +66,16 @@ public class CacheInstanceTest {
|
|||||||
"", iGroup, "0", new InetSocketAddress("127.0.0.1", 8080), new ClientAddress(), "TCP", 1, 16);
|
"", iGroup, "0", new InetSocketAddress("127.0.0.1", 8080), new ClientAddress(), "TCP", 1, 16);
|
||||||
CacheInstance instance = Sncp.createLocalService(
|
CacheInstance instance = Sncp.createLocalService(
|
||||||
null, "", serviceClass, boost, resourceFactory, grous, client, null, null, null);
|
null, "", serviceClass, boost, resourceFactory, grous, client, null, null, null);
|
||||||
// System.out.println(instance.getName());
|
resourceFactory.inject(instance);
|
||||||
|
CacheInstance instance2 = Sncp.createLocalService(
|
||||||
|
null, "", serviceClass, boost, resourceFactory2, grous, client, null, null, null);
|
||||||
|
resourceFactory2.inject(instance2);
|
||||||
|
System.out.println(instance.getName2());
|
||||||
|
Assertions.assertEquals("haha", instance.getName2());
|
||||||
|
Assertions.assertEquals("haha", instance2.getName2());
|
||||||
|
instance.updateName();
|
||||||
|
Assertions.assertEquals("gege", instance.getName2());
|
||||||
|
Assertions.assertEquals("gege", instance2.getName2());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user