at org.springframework.data.mongodb.core.mapreduce.MapReduceResults.parseTiming(MapReduceResults.java:80)
at org.springframework.data.mongodb.core.mapreduce.MapReduceResults.<init>(MapReduceResults.java:49)
at org.springframework.data.mongodb.core.MongoTemplate.mapReduce(MongoTemplate.java:1026)
at org.springframework.data.mongodb.core.MongoTemplate.mapReduce(MongoTemplate.java:981)
at com.jd.console.service.log.TestLogServiceImpl.mrGroupWfNamesTest(TestLogServiceImpl.java:95)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
由于依赖的时候1.0.1.RELEASE
<dependency>
<artifactId>spring-data-mongodb</artifactId>
<groupId>org.springframework.data</groupId>
<version>1.0.1.RELEASE</version>
</dependency>
在源码中
org.springframework.data.mongodb.core.mapreduce.MapReduceResults
中新建对象的构造器,new的时候调用parseTime
public MapReduceResults(List<T> mappedResults, DBObject rawResults) {
Assert.notNull(mappedResults);
Assert.notNull(rawResults);
this.mappedResults = mappedResults;
this.rawResults = rawResults;
parseTiming(rawResults);
parseCounts(rawResults);
if (rawResults.get("result") != null) {
this.outputCollection = (String) rawResults.get("result");
}
}
这个 在转换parseTime的时候数据
rawResults如下数据
{ "serverUsed" : "192.168.232.62:27017" , "results" : [//数据太多省略] , "timeMillis" : 39780 , "timing" : { "mapTime" : 28962 , "emitLoop" : 39780 , "reduceTime" : 2861 , "mode" : "mixed" , "total" : 39780} , "counts" : { "input" : 1922720 , "emit" : 1922720 , "reduce" : 19236 , "output" : 9} , "ok" : 1.0}
这行代码(Long) timing.get("mapTime")强转的时候就报错了。
if (timing != null) {
if (timing.get("mapTime") != null && timing.get("emitLoop") != null && timing.get("total") != null) {
mapReduceTiming = new MapReduceTiming((Long) timing.get("mapTime"), (Integer) timing.get("emitLoop"),
(Integer) timing.get("total"));
}
} else {
mapReduceTiming = new MapReduceTiming(-1, -1, -1);
}
个人修改成了1.0.3就在没有那个问题了。
<dependency>
<artifactId>spring-data-mongodb</artifactId>
<groupId>org.springframework.data</groupId>
<version>1.0.3.RELEASE</version>
</dependency>
运行成功。
但是接下来又碰到了一个错
Caused by: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer
at org.springframework.data.mongodb.core.mapreduce.MapReduceResults.parseCounts(MapReduceResults.java:125)
at org.springframework.data.mongodb.core.mapreduce.MapReduceResults.<init>(MapReduceResults.java:54)
at org.springframework.data.mongodb.core.MongoTemplate.mapReduce(MongoTemplate.java:1025)
at org.springframework.data.mongodb.core.MongoTemplate.mapReduce(MongoTemplate.java:990)
看了一下这个错误我去还是在构造对象的时候parseCounts造成的,类似上边那个问题。。。。bug啊。。。。
悲了个剧了直接改成1.2x的版本,
<dependency>
<artifactId>spring-data-mongodb</artifactId>
<groupId>org.springframework.data</groupId>
<version>1.2.1.RELEASE</version>
</dependency>
接下来那个问题就再没有了。