Apache Geode - 使用来自客户端的相同代码在基于 DUnit 的测试 Server/Remote 服务器上创建区域
Apache Geode - Creating region on DUnit Based Test Server/Remote Server with same code from client
我正在尝试重用以下文档中的代码:https://geode.apache.org/docs/guide/11/developing/region_options/dynamic_region_creation.html
我遇到的第一个问题是
Cache cache = CacheFactory.getAnyInstance();
Region<String,RegionAttributes<?,?>> regionAttributesMetadataRegion = createRegionAttributesMetadataRegion(cache);
不应在构造函数中执行。如果是,代码在客户端实例中执行,它在非服务器上失败 error.When 我收到此修复
[fatal 2021/02/15 16:38:24.915 EET <ServerConnection on port 40527 Thread 1> tid=81] Serialization filter is rejecting class org.restcomm.cache.geode.CreateRegionFunction
java.lang.Exception:
at org.apache.geode.internal.ObjectInputStreamFilterWrapper.lambda$createSerializationFilter[=12=](ObjectInputStreamFilterWrapper.java:233)
问题是代码正在 dunit MemberVM 上执行,而所需的 class 实际上是测试正在执行的包的一部分。
所以我想我应该以某种方式将 classes(或者可能是 jar)分别注册到 dunit MemberVM。怎么做到的?
另一个问题是:目前代码正在检查区域是否存在,如果不存在则调用该方法。在这两种情况下,它还会尝试创建 clientRegion。问题是这是否是正确的做法?
Region<?,?> cache = instance.getRegion(name);
if(cache==null) {
Execution execution = FunctionService.onServers(instance);
ArrayList argList = new ArrayList();
argList.add(name);
Function function = new CreateRegionFunction();
execution.setArguments(argList).execute(function).getResult();
}
ClientRegionFactory<Object, Object> cf=this.instance.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).addCacheListener(new ExtendedCacheListener());
this.cache = cf.create(name);
BR
尤连奥法
The first problem that i met is that
Cache cache = CacheFactory.getAnyInstance();
should not be executed in constructor. In case it is , the code is executed in client instance , it is failed on not server error.When this fixed i receive
在服务器端注册 Function
后,您可以通过 ID
执行它,而不是通过网络发送对象(因此您不需要在客户端实例化该函数),在这种情况下,您还将避免 Serialization filter
错误。例如,FunctionService.onServers(instance).execute(CreateRegionFunction.ID)
.
The problem is that code is getting executed on dunit MemberVM and the required class is actually the part of the package under which the test is getting executed. So i guess i should somehow register the classes ( or may be jar ) separately to dunit MemberVM. How it can be done?
确实,出于安全原因 Geode
不允许任意序列化/反序列化 类。内部 Geode
分布式测试使用 MemberVM
并设置一个特殊的 属性 (serializable-object-filter
) 来规避这个问题。 Here's 如何在自己的测试中实现这一目标的示例。
Another question is: currently the code is checking if the region exists and if not it calls the method. In both cases it also tries to create the clientRegion. The question is whether this is a correct approach?
如果客户端应用程序使用动态创建的区域,那么是的,您应该创建它,否则您将无法使用它。
附带说明一下,Geode
在创建 Region
时实现了很多内部逻辑,所以我不建议您自己动态创建区域。相反,建议使用 gfsh create region
command directly, or look at how it works internally (see here) 并尝试重新使用它。
我正在尝试重用以下文档中的代码:https://geode.apache.org/docs/guide/11/developing/region_options/dynamic_region_creation.html
我遇到的第一个问题是
Cache cache = CacheFactory.getAnyInstance();
Region<String,RegionAttributes<?,?>> regionAttributesMetadataRegion = createRegionAttributesMetadataRegion(cache);
不应在构造函数中执行。如果是,代码在客户端实例中执行,它在非服务器上失败 error.When 我收到此修复
[fatal 2021/02/15 16:38:24.915 EET <ServerConnection on port 40527 Thread 1> tid=81] Serialization filter is rejecting class org.restcomm.cache.geode.CreateRegionFunction
java.lang.Exception:
at org.apache.geode.internal.ObjectInputStreamFilterWrapper.lambda$createSerializationFilter[=12=](ObjectInputStreamFilterWrapper.java:233)
问题是代码正在 dunit MemberVM 上执行,而所需的 class 实际上是测试正在执行的包的一部分。 所以我想我应该以某种方式将 classes(或者可能是 jar)分别注册到 dunit MemberVM。怎么做到的?
另一个问题是:目前代码正在检查区域是否存在,如果不存在则调用该方法。在这两种情况下,它还会尝试创建 clientRegion。问题是这是否是正确的做法?
Region<?,?> cache = instance.getRegion(name);
if(cache==null) {
Execution execution = FunctionService.onServers(instance);
ArrayList argList = new ArrayList();
argList.add(name);
Function function = new CreateRegionFunction();
execution.setArguments(argList).execute(function).getResult();
}
ClientRegionFactory<Object, Object> cf=this.instance.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).addCacheListener(new ExtendedCacheListener());
this.cache = cf.create(name);
BR 尤连奥法
The first problem that i met is that Cache cache = CacheFactory.getAnyInstance(); should not be executed in constructor. In case it is , the code is executed in client instance , it is failed on not server error.When this fixed i receive
在服务器端注册 Function
后,您可以通过 ID
执行它,而不是通过网络发送对象(因此您不需要在客户端实例化该函数),在这种情况下,您还将避免 Serialization filter
错误。例如,FunctionService.onServers(instance).execute(CreateRegionFunction.ID)
.
The problem is that code is getting executed on dunit MemberVM and the required class is actually the part of the package under which the test is getting executed. So i guess i should somehow register the classes ( or may be jar ) separately to dunit MemberVM. How it can be done?
确实,出于安全原因 Geode
不允许任意序列化/反序列化 类。内部 Geode
分布式测试使用 MemberVM
并设置一个特殊的 属性 (serializable-object-filter
) 来规避这个问题。 Here's 如何在自己的测试中实现这一目标的示例。
Another question is: currently the code is checking if the region exists and if not it calls the method. In both cases it also tries to create the clientRegion. The question is whether this is a correct approach?
如果客户端应用程序使用动态创建的区域,那么是的,您应该创建它,否则您将无法使用它。
附带说明一下,Geode
在创建 Region
时实现了很多内部逻辑,所以我不建议您自己动态创建区域。相反,建议使用 gfsh create region
command directly, or look at how it works internally (see here) 并尝试重新使用它。