尝试在基本primitype类型和对象
上执行增量操作时出错 @Test
public void TestDeltaOnField() {
String name = "SreeHari";
ROCCacheConfiguration<String, String> rc1 = new ROCCacheConfiguration<>();
rc1.setName("seventhCache");
ROCCache<String, String> r1 = rocCachemanager.createCache(rc1);
r1.put("a", name);
assertEquals(r1.get("a"), "SreeHari");
rocCachemanager.withKeepBinary(r1.getName()).invoke("a", (entry, args) -> {
String a = (String) entry.getValue();
entry.setValue(a = "Hari");
return null;
});
assertEquals(r1.get("a"), "Hari");
r1.replace("a", "Hari", "Hari1");
assertEquals(r1.get("a"), "Hari1");
rocCachemanager.destroyCache("seventhCache");
}
@Test
public void TestDeltaOnPojoFields() {
TestPojo t1 = new TestPojo(1, "SreeHari1");
TestPojo t2 = new TestPojo(2, "Hari1");
TestPojo t3 = new TestPojo(3, "SreeHari2");
TestPojo t4 = new TestPojo(4, "Hari2");
TestPojo t5 = new TestPojo(5, "SreeHari3");
TestPojo t6 = new TestPojo(6, "Hari3");
TestPojo t7 = new TestPojo(7, "SreeHari4");
TestPojo t8 = new TestPojo(8, "Hari4");
ROCCacheConfiguration<String, TestPojo> rc1 = new ROCCacheConfiguration<>();
rc1.setName("eighthCache");
ROCCache<String, TestPojo> r1 = rocCachemanager.createCache(rc1);
r1.put("a", t1);
r1.put("b", t2);
r1.put("c", t3);
r1.put("d", t4);
assertEquals(r1.get("a").getName(), "SreeHari1");
rocCachemanager.withKeepBinary(r1.getName()).invoke("a", (entry, args) -> {
BinaryObjectBuilder bldr = ((BinaryObject) entry.getValue()).toBuilder();
// Update the field in the builder.
bldr.setField("name", "SreeHari3");
int val = bldr.getField("id");
bldr.setField("id", val + 1);
// Set new value to the entry.
entry.setValue(bldr.build());
return null;
});
assertEquals(r1.get("a").getName(), "SreeHari3");
assertEquals(r1.get("a").getId(), 2);
rocCachemanager.destroyCache("eighthCache");
}
@Test
public void TestDeltaOnAllPojoFields() {
Set<String> key = new HashSet<String>();
key.add("a");
key.add("b");
key.add("c");
key.add("d");
TestPojo t1 = new TestPojo(1, "SreeHari1");
TestPojo t2 = new TestPojo(2, "Hari1");
TestPojo t3 = new TestPojo(3, "SreeHari2");
TestPojo t4 = new TestPojo(4, "Hari2");
ROCCacheConfiguration<String, TestPojo> rc1 = new ROCCacheConfiguration<>();
rc1.setName("ninethCache");
ROCCache<String, TestPojo> r1 = rocCachemanager.createCache(rc1);
r1.put("a", t1);
r1.put("b", t2);
r1.put("c", t3);
r1.put("d", t4);
assertEquals(r1.get("a").getName(), "SreeHari1");
rocCachemanager.withKeepBinary(r1.getName()).invokeAll(key, (entry, args) -> {
BinaryObjectBuilder bldr = ((BinaryObject) entry.getValue()).toBuilder();
// Update the field in the builder.
bldr.setField("name", "SreeHari3");
// Set new value to the entry.
entry.setValue(bldr.build());
return null;
});
assertEquals(r1.get("b").getName(), "SreeHari3");
rocCachemanager.destroyCache("eigthCache");
r1.replace("b", t1);
assertEquals(r1.get("b").getName(), "SreeHari1");
rocCachemanager.destroyCache("nineththCache");
}
@Test
public void testDeltaOnAllListOfPojoFields() {
Set<String> key = new HashSet<String>();
key.add("a");
key.add("b");
key.add("c");
key.add("d");
TestPojo t1 = new TestPojo(1, "SreeHari1");
TestPojo t2 = new TestPojo(2, "Hari1");
TestPojo t3 = new TestPojo(3, "SreeHari2");
TestPojo t4 = new TestPojo(4, "Hari2");
TestPojo t5 = new TestPojo(5, "SreeHari3");
TestPojo t6 = new TestPojo(6, "Hari3");
TestPojo t7 = new TestPojo(7, "SreeHari4");
TestPojo t8 = new TestPojo(8, "Hari4");
List<TestPojo> listob1 = new ArrayList<TestPojo>();
listob1.add(t1);
listob1.add(t2);
List<TestPojo> listob2 = new ArrayList<TestPojo>();
listob2.add(t3);
listob2.add(t4);
List<TestPojo> listob3 = new ArrayList<TestPojo>();
listob3.add(t5);
listob3.add(t6);
List<TestPojo> listob4 = new ArrayList<TestPojo>();
listob4.add(t7);
listob4.add(t8);
Map<String, List<TestPojo>> igMap = new HashMap<String, List<TestPojo>>();
igMap.put("a", listob1);
igMap.put("b", listob2);
igMap.put("c", listob3);
igMap.put("d", listob4);
ROCCacheConfiguration<String, List<TestPojo>> rc1 = new ROCCacheConfiguration<>();
rc1.setName("tenthCache");
ROCCache<String, List<TestPojo>> r1 = (ROCCache<String, List<TestPojo>>) rocCachemanager.createCache(rc1);
r1.putAll(igMap);
rocCachemanager.withKeepBinary(r1.getName()).invokeAll(key, (entry, args) -> {
BinaryObjectBuilder bldr = ((BinaryObject) entry.getValue()).toBuilder();
// Update the field in the builder.
bldr.setField("name", "SreeHari3");
// Set new value to the entry.
entry.setValue(bldr.build());
return null;
});
assertEquals(r1.getAll(key).get("a").get(0).getName(), "SreeHari1");
rocCachemanager.destroyCache("tenthCache");
}
错误堆栈跟踪如下
javax.cache.CacheException: class org.apache.ignite.IgniteCheckedException:
cache.ROCCacheTest $$ Lambda $ 9/1985869725 at org.apache.ignite.internal.processors.cache.GridCacheUtils.convertToCacheException(GridCacheUtils.java:1618) 在 org.apache.ignite.internal.processors.cache.IgniteCacheProxy.cacheException(IgniteCacheProxy.java:1841) 在 org.apache.ignite.internal.processors.cache.IgniteCacheProxy.invokeAll(IgniteCacheProxy.java:1544) 在cache.ROCCache.invokeAll(ROCCache.java:129)at cache.ROCCacheTest.testDeltaOnAllListOfPojoFields(ROCCacheTest.java:529) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.lang.reflect.Method.invoke(Method.java:497)at org.junit.runners.model.FrameworkMethod $ 1.runReflectiveCall(FrameworkMethod.java:50) 在 org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 在 org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) 在 org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) 在 org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75) 在 org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86) 在 org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84) 在org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:254) 在 org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89) 在org.junit.runners.ParentRunner $ 3.run(ParentRunner.java:290)at at org.junit.runners.ParentRunner $ 1.schedule(ParentRunner.java:71)at at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)at at org.junit.runners.ParentRunner.access $ 000(ParentRunner.java:58)at at org.junit.runners.ParentRunner $ 2.evaluate(ParentRunner.java:268)at at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) 在 org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) 在org.junit.runners.ParentRunner.run(ParentRunner.java:363)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:193) 在 org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) 在 org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) 引起:class org.apache.ignite.IgniteCheckedException:cache.ROCCacheTest $$ Lambda $ 9/1985869725 在org.apache.ignite.internal.processors.cache.GridCacheIoManager.unmarshall(GridCacheIoManager.java:1044) 在org.apache.ignite.internal.processors.cache.GridCacheIoManager.onMessage0(GridCacheIoManager.java:275) 在org.apache.ignite.internal.processors.cache.GridCacheIoManager.handleMessage(GridCacheIoManager.java:204) at org.apache.ignite.internal.processors.cache.GridCacheIoManager.access $ 000(GridCacheIoManager.java:80) 在org.apache.ignite.internal.processors.cache.GridCacheIoManager $ 1.onMessage(GridCacheIoManager.java:163) 在org.apache.ignite.internal.managers.communication.GridIoManager.processRegularMessage0(GridIoManager.java:821) 在org.apache.ignite.internal.managers.communication.GridIoManager.access $ 1600(GridIoManager.java:103) 在org.apache.ignite.internal.managers.communication.GridIoManager $ 5.run(GridIoManager.java:784) 在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617) 在java.lang.Thread.run(Thread.java:745) 引起:class org.apache.ignite.binary.BinaryInvalidTypeException: cache.ROCCacheTest $$ LAMBDA $1985869725分之9 at org.apache.ignite.internal.binary.BinaryContext.descriptorForTypeId(BinaryContext.java:492) at org.apache.ignite.internal.binary.BinaryContext.descriptorForTypeId(BinaryContext.java:489) at org.apache.ignite.internal.binary.BinaryReaderExImpl.deserialize(BinaryReaderExImpl.java:1443) 在org.apache.ignite.internal.binary.GridBinaryMarshaller.deserialize(GridBinaryMarshaller.java:292) 在org.apache.ignite.internal.binary.BinaryMarshaller.unmarshal(BinaryMarshaller.java:112) 在org.apache.ignite.internal.processors.cache.GridCacheMessage.unmarshalCollection(GridCacheMessage.java:606) at org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridNearAtomicUpdateRequest.finishUnmarshal(GridNearAtomicUpdateRequest.java:621) 在org.apache.ignite.internal.processors.cache.GridCacheIoManager.unmarshall(GridCacheIoManager.java:1038) ......还有10个 引起:java.lang.ClassNotFoundException:cache.ROCCacheTest $$ Lambda $ 9/1985869725 at java.lang.Class.forName0(Native Method) 在java.lang.Class.forName(Class.java:340) at org.apache.ignite.internal.util.IgniteUtils.forName(IgniteUtils.java:8172) at org.apache.ignite.internal.MarshallerContextAdapter.getClass(MarshallerContextAdapter.java:185) at org.apache.ignite.internal.binary.BinaryContext.descriptorForTypeId(BinaryContext.java:483) ......还有17个
之前所有的测试都运行良好。尝试进行客户端和服务器设置后,测试失败,现在当相同的两个系统用作服务器或配置处于仅服务器模式时,测试失败。
配置如下
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd">
<!-- Datasource for sample in-memory H2 database. -->
<bean id="h2-example-db" class="org.h2.jdbcx.JdbcDataSource">
<property name="URL" value="jdbc:h2:tcp://localhost/mem:ExampleDb" />
<property name="user" value="sa" />
</bean>
<bean abstract="true" id="ignite.cfg"
class="org.apache.ignite.configuration.IgniteConfiguration">
<!-- Set to true to enable distributed class loading for examples, default
is false. -->
<property name="peerClassLoadingEnabled" value="false" />
<!-- Enable task execution events for examples. -->
<property name="includeEventTypes">
<list>
<!--Task execution events -->
<util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_STARTED" />
<util:constant
static-field="org.apache.ignite.events.EventType.EVT_TASK_FINISHED" />
<util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_FAILED" />
<util:constant
static-field="org.apache.ignite.events.EventType.EVT_TASK_TIMEDOUT" />
<util:constant
static-field="org.apache.ignite.events.EventType.EVT_TASK_SESSION_ATTR_SET" />
<util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_REDUCED" />
<!--Cache events -->
<util:constant
static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_PUT" />
<util:constant
static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_READ" />
<util:constant
static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_REMOVED" />
</list>
</property>
<!-- Explicitly configure TCP discovery SPI to provide list of initial
nodes. -->
<property name="discoverySpi">
<bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
<property name="joinTimeout" value="60000" />
<property name="ipFinder">
<!-- Ignite provides several options for automatic discovery that can
be used instead os static IP based discovery. For information on all options
refer to our documentation: http://apacheignite.readme.io/docs/cluster-config -->
<!-- Uncomment static IP finder to enable static-based discovery of
initial nodes. -->
<!--<bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder"> -->
<bean
class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
<!-- <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder"> -->
<property name="addresses">
<list>
<!-- In distributed environment, replace with actual host IP address. -->
<value>10.113.56.231:47500..47509</value>
<value>10.113.56.110:47500..47509</value>
</list>
</property>
</bean>
</property>
</bean>
</property>
<!-- property name="marshaller"> <bean class="com.esotericsoftware.kryo.serializers.DefaultSerializers">
<property name="requireSerializable" value="false" /> </bean> </property -->
<!--property name="binaryConfiguration"> <bean class="org.apache.ignite.configuration.BinaryConfiguration">
<property name="typeConfigurations"> <list> <bean class="org.apache.ignite.binary.BinaryTypeConfiguration">
<property name="typeName" value="testPojo" /> <property name="serializer">
<bean class="com.esotericsoftware.kryo.serializers.DefaultSerializers" />
</property> </bean> </list> </property> </bean> </property -->
</bean>
</beans>
答案 0 :(得分:1)
看起来拓扑中的节点没有类路径上的所有必需类。在您的情况下,您必须部署声明条目处理器lambda的类。
另一种选择是打开对等类加载:
<property name="peerClassLoadingEnabled" value="true"/>