我想在Elasticsearch中执行单元测试,因为我正在使用public class DateTimeRange
{
private DateTime Start { get; set; }
private DateTime End { get; set; }
public DateTimeRange(DateTime start, DateTime end)
{
Start = start;
End = end;
}
public int DayOffsCount()
{
var current = Start;
var dayOffsCount = 0;
while (current < End)
{
if (IsDayOff(current))
{
dayOffsCount++;
}
current = current.AddDays(1);
}
return dayOffsCount;
}
}
public bool IsDayOff(DateTime dt)
{
if (dt.DayOfWeek == DayOfWeek.Saturday || dt.DayOfWeek == DayOfWeek.Sunday)
return true;
return IsHoliday(dt);
}
我正在使用Java-test-framework
并参考这些链接寻求帮助
https://www.elastic.co/guide/en/elasticsearch/reference/1.6/using-elasticsearch-test-classes.html
https://github.com/elastic/elasticsearch/blob/master/core/src/test/java/org/elasticsearch/action/search/SearchRequestBuilderTests.java
这是代码
Elasticsearch-1.6.0
我收到此异常
class CampaignESTest extends ESTestCase {
def getCLient():MockTransportClient={
val settings = Settings.builder()
.put(Environment.PATH_HOME_SETTING.getKey(), Files.createTempDir().toString())
.build();
val client = new MockTransportClient(settings);
client
}
}
class CampaignTestSearch extends PlaySpec{
val client=new CampaignESTest
val response = client.prepareSearch("dbtest")
.setTypes(CAMPAIGN_COLLECTION_NAME)
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.addFields("uuid","campaignName","artworkID","activationDate","_source")
.setQuery(query)
.execute()
.actionGet()
}
在此行中获得例外
Exception encountered when attempting to run a suite with class name: org.scalatest.DeferredAbortedSuite *** ABORTED ***
[info] java.lang.NoClassDefFoundError: org/apache/lucene/codecs/simpletext/SimpleTextCodec
[info] at org.apache.lucene.util.LuceneTestCase.<clinit>(LuceneTestCase.java:616)
[info] at testcontrollers.campaign.CampaignTestSearch.<init>(CampaignTestSearch.scala:40)
[info] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[info] at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
[info] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
[info] at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
[info] at java.lang.Class.newInstance(Class.java:442)
[info] at org.scalatest.tools.Framework$ScalaTestTask.execute(Framework.scala:468)
[info] at sbt.ForkMain$Run$2.call(ForkMain.java:296)
[info] at sbt.ForkMain$Run$2.call(ForkMain.java:286)
[info] ...
[info] Cause: java.lang.ClassNotFoundException: org.apache.lucene.codecs.simpletext.SimpleTextCodec
[info] at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
[info] at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[info] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
[info] at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[info] at org.apache.lucene.util.LuceneTestCase.<clinit>(LuceneTestCase.java:616)
[info] at testcontrollers.campaign.CampaignTestSearch.<init>(CampaignTestSearch.scala:40)
[info] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[info] at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
[info] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
[info] at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
[info] ...
课程val client=new CampaignESTest
中的
这是CampaignTestSearch
文件
build.sbt
我怀疑异常的原因可能是由于某些版本的依赖项,任何人都可以帮助使用正确的库依赖版本来使其工作或者是我缺少的其他东西
答案 0 :(得分:1)
两个问题:
SimpleTextCodec
位于codecs,而不是后退编解码器。
您正在使用lucene 5.4.0中的jar。切勿混合搭配你的lucene版本。 Elasticsearch 1.6.0旨在与lucene 4.10.4一起使用。在lucene 5.4.0的罐子里混合只会给你带来麻烦。