通常我不提供点火配置。我只是这样做:
this.ignite = Ignition.getOrStart(new IgniteConfiguration());
并对点燃执行一些操作:
this.ignite.getOrCreateCache(Identifiers.BRAND_IGNITE_ITEM_CACHE).removeAll();
this.ignite.getOrCreateCache(Identifiers.BRAND_IGNITE_ITEM_CACHE).putAll(map);
工作正常。出于测试目的,我现在想要使用ignite创建一个内存数据库,以便拥有一个数据库,我可以从中将项目加载到我的ignite缓存中。所以我创建了一个jdbc连接:
public class DefaultConnection {
private static Connection connection = null;
public static Connection getConnection(String driverName, String host, String user, String password) throws SQLException {
if (connection != null) {
return connection;
} else {
try {
Class.forName(driverName);
} catch (ClassNotFoundException e) {
log.severe(e.getMessage());
return null;
}
if (user == null || password == null) {
return DriverManager.getConnection(host);
}
return DriverManager.getConnection(host, user, password);
}
}
}
this.DRIVER_NAME = "org.apache.ignite.IgniteJdbcThinDriver";
this.HOST = "jdbc:ignite:thin://127.0.0.1/";
this.connection = DefaultConnection.getConnection(DRIVER_NAME, HOST, null, null);
... // create tables and insert some data
注意我还没有使用.loadCache(null)
上的ignite.getOrCreateCache("MyCache")
函数将数据从数据库加载到缓存中。我刚刚创建了一些包含一些数据的表。
当我现在想要在空缓存上执行操作时,就像一个简单的get:
this.ignite = Ignition.getOrStart(new IgniteConfiguration());
this.ignite.getOrCreateCache("MyCache").get("123456");
我收到以下错误:
reactor.core.Exceptions$ErrorCallbackNotImplemented: java.lang.IllegalStateException: Grid is in invalid state to perform this operation. It either not started yet or has already being or have stopped [igniteInstanceName=null, state=STOPPED]
Caused by: java.lang.IllegalStateException: Grid is in invalid state to perform this operation. It either not started yet or has already being or have stopped [igniteInstanceName=null, state=STOPPED]
at org.apache.ignite.internal.GridKernalGatewayImpl.illegalState(GridKernalGatewayImpl.java:201)
at org.apache.ignite.internal.GridKernalGatewayImpl.readLock(GridKernalGatewayImpl.java:95)
at org.apache.ignite.internal.IgniteKernal.guard(IgniteKernal.java:3709)
at org.apache.ignite.internal.IgniteKernal.getOrCreateCache(IgniteKernal.java:3142)
at de.test.MyService.publishItemsFromCacheQuery(ProviderService.java:335)
at de.test.MyService.lambda$null$12(ProviderService.java:286)
at reactor.core.publisher.FluxCreate.subscribe(FluxCreate.java:92)
at reactor.core.publisher.Flux.subscribe(Flux.java:6633)
at reactor.core.publisher.Flux.subscribeWith(Flux.java:6800)
at reactor.core.publisher.Flux.subscribe(Flux.java:6626)
at reactor.core.publisher.Flux.subscribe(Flux.java:6590)
at reactor.core.publisher.Flux.subscribe(Flux.java:6533)
at de.test.MyService.lambda$null$14(ProviderService.java:286)
at reactor.core.publisher.LambdaMonoSubscriber.onNext(LambdaMonoSubscriber.java:137)
at reactor.core.publisher.Operators$ScalarSubscription.request(Operators.java:1626)
at reactor.core.publisher.LambdaMonoSubscriber.onSubscribe(LambdaMonoSubscriber.java:87)
at reactor.core.publisher.MonoJust.subscribe(MonoJust.java:54)
at reactor.core.publisher.Mono.subscribe(Mono.java:3006)
at reactor.core.publisher.Mono.subscribeWith(Mono.java:3114)
at reactor.core.publisher.Mono.subscribe(Mono.java:3000)
at reactor.core.publisher.Mono.subscribe(Mono.java:2967)
at reactor.core.publisher.Mono.subscribe(Mono.java:2914)
at de.test.MyService.lambda$getAverageBenchmarkItems$15(ProviderService.java:276)
at reactor.core.publisher.FluxCreate.subscribe(FluxCreate.java:92)
at reactor.core.publisher.MonoCollect.subscribe(MonoCollect.java:66)
at reactor.core.publisher.Mono.block(Mono.java:1161)
at de.test.MyServiceTest.getAverageBenchmarkItemsNegative(ProviderServiceTest.java:695)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:73)
at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:83)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:114)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:57)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:66)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
at com.sun.proxy.$Proxy1.processTestClass(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:109)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:146)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:128)
at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:404)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:46)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
at java.lang.Thread.run(Thread.java:748)
如果我没有创建一个jdbc连接来点燃一切正常。
“MyCache”的缓存配置示例:
private CacheConfiguration<String, MyItem> getCacheConfiguration() {
final CacheConfiguration<String, MyItem> cacheConfiguration = new CacheConfiguration<>("MyCache");
cacheConfiguration.setName("MyCache");
cacheConfiguration.setIndexedTypes(String.class, MyItem.class);
cacheConfiguration.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
cacheConfiguration.setCacheStoreFactory(FactoryBuilder.factoryOf(MyItemCacheStore.class.getName()));
cacheConfiguration.setReadThrough(true);
cacheConfiguration.setWriteThrough(true);
cacheConfiguration.setCopyOnRead(false);
cacheConfiguration.setCacheMode(CacheMode.PARTITIONED);
cacheConfiguration.setOnheapCacheEnabled(true);
cacheConfiguration.setEvictionPolicy(new LruEvictionPolicy());
return cacheConfiguration;
}
当有一个打开的jdbc连接点燃时,为什么isnt点燃能够构建网格?
修改
一些额外的信息:我只需要jdbc连接进行单元测试。此异常只出现在使用gradlew test
如果我运行单元测试“正常”方式一切正常
编辑2
注意:仅在运行gradlew test
时以及使用@ActiveProfiles("test")
注释服务测试类时才会显示异常。在其他情况下