This commit is contained in:
redkale
2024-06-06 23:53:52 +08:00
parent f0bc867220
commit 1c07fcc6fa
2 changed files with 28 additions and 3 deletions

View File

@@ -40,6 +40,10 @@ public class CacheInstance implements Service {
return "haha";
}
public void updateName() {
cacheManager.bothSet("name", String.class, "gege", Duration.ofMillis(600), Duration.ofMillis(600));
}
@Cached(key = "name", localExpire = "30", remoteExpire = "60")
public String getName2() throws RedkaleException {
return "haha";

View File

@@ -4,6 +4,7 @@
package org.redkale.test.cache;
import java.net.InetSocketAddress;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.redkale.cache.CacheManager;
@@ -26,6 +27,10 @@ public class CacheInstanceTest {
private static CacheManagerService manager;
private static ResourceFactory resourceFactory2;
private static CacheManagerService manager2;
public static void main(String[] args) throws Throwable {
CacheInstanceTest test = new CacheInstanceTest();
init();
@@ -35,13 +40,20 @@ public class CacheInstanceTest {
@BeforeAll
public static void init() throws Exception {
resourceFactory = ResourceFactory.create();
resourceFactory.register(new Environment());
CacheMemorySource remoteSource = new CacheMemorySource("cache-remote");
remoteSource.init(null);
resourceFactory = ResourceFactory.create();
resourceFactory.register(new Environment());
manager = CacheManagerService.create(remoteSource);
manager.init(null);
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
@@ -54,7 +66,16 @@ public class CacheInstanceTest {
"", iGroup, "0", new InetSocketAddress("127.0.0.1", 8080), new ClientAddress(), "TCP", 1, 16);
CacheInstance instance = Sncp.createLocalService(
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