How to use ESIntegTestCase in elasticsearch 6.6.1

Hi,
When I run the source code:

import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
import org.elasticsearch.test.ESIntegTestCase.Scope;

import java.util.Collection;
import java.util.Collections;

import org.elasticsearch.cluster.metadata.IndexMetaData;

@ClusterScope(scope = Scope.SUITE, numDataNodes = 1, numClientNodes = 0, transportClientRatio = 0, supportsDedicatedMasters = false)
public class AbstractSearchScriptTestCase extends ESIntegTestCase {

	@Override
	protected Settings nodeSettings(int nodeOrdinal) {
		return Settings.builder().put(super.nodeSettings(nodeOrdinal))
			.put("network.host", "localhost")
			.put("http.port", "9200")
			.build();
	}
	
    @Override
    public Settings indexSettings() {
        return Settings.builder()
	        .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
	        .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
	        .build();
    }
    
    @Override
    protected Collection<Class<? extends Plugin>> nodePlugins() {
    	return Collections.singletonList(RecurringPlugin.class);
    }
}

I get an error:

Exception in thread "Thread-1" java.lang.NoClassDefFoundError: Could not initialize class org.elasticsearch.test.ESTestCase
	at java.lang.Thread.run(Unknown Source)
	Suppressed: java.lang.IllegalStateException: No context information for thread: Thread[id=13, name=Thread-1, state=RUNNABLE, group=TGRP-RecurringElasticsearchTest]. Is this thread running under a class com.carrotsearch.randomizedtesting.RandomizedRunner runner context? Add @RunWith(class com.carrotsearch.randomizedtesting.RandomizedRunner.class) to your test class. Make sure your code accesses random contexts within @BeforeClass and @AfterClass boundary (for example, static test class initializers are not permitted to access random contexts).
		at com.carrotsearch.randomizedtesting.RandomizedContext.context(RandomizedContext.java:249)
		at com.carrotsearch.randomizedtesting.RandomizedContext.current(RandomizedContext.java:134)
		at com.carrotsearch.randomizedtesting.RandomizedRunner.augmentStackTrace(RandomizedRunner.java:1885)
		at com.carrotsearch.randomizedtesting.RunnerThreadGroup.uncaughtException(RunnerThreadGroup.java:20)
		at java.lang.Thread.dispatchUncaughtException(Unknown Source)

How to fix this error?

Did you try what the error message says?

Add @RunWith(class com.carrotsearch.randomizedtesting.RandomizedRunner.class) to your test class.

We use randomization within our test framework.

Hello, if I try it with simple test and with RunWith and it keeps presenting the same error.

Simple test

import org.elasticsearch.test.ESIntegTestCase;
import org.junit.Test;

public class RecurringElasticsearchTest extends ESIntegTestCase {

	@Test
    public void test() throws Exception {
		System.out.println("Hello");
    }
	
}

And RunWith

import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
import org.elasticsearch.test.ESIntegTestCase.Scope;
import org.elasticsearch.test.junit.annotations.TestLogging;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

@TestLogging("_root:DEBUG")
@ClusterScope(scope = Scope.SUITE)
@RunWith(com.carrotsearch.randomizedtesting.RandomizedRunner.class)
public class RecurringIntTest extends ESIntegTestCase {

	@Override
	protected Settings nodeSettings(int nodeOrdinal) {
		return Settings.builder().put(super.nodeSettings(nodeOrdinal)).build();
	}

	@Before
	public void setUp() throws Exception {
		super.setUp();
	}
	
	@Test
	public void testRecurringScript() throws Exception {
		Assert.assertTrue(true);
	}
}

What will happen?

Sorry, but you have not provided enough information for us to debug this. Would you please provide a full reproduction. Code is not enough, since we don't know how you're invoking the tests, what runner you are using, etc.

Hello, I already corrected that error but now I present this error
and the error that indicates to me is a blank line nothing more:

* What went wrong:
Execution failed for task ':forbiddenPatterns'.
> Found invalid patterns:
  - tab on line 28 of src/test/java/org/devmaster/elasticsearch/plugin/RecurringSearchScriptTests.java

when executing

./gradlew clean build

Or

gradle clean build

Have a clue why that error?

Most likely a tab instead of spaces.

wow eliminate all the tabs, that is to say without space enters does not have good style the code but good.

Now I have this error. Can you help me know what it is? por favor. :smiley:

$ ./gradlew clean build

> Configure project :
=======================================
Elasticsearch Build Hamster says Hello!
  Gradle Version        : 5.2.1
  OS Info               : Windows 7 6.1 (amd64)
  JDK Version           : 11 (Oracle Corporation 11.0.2 [Java HotSpot(TM) 64-Bit Server VM 11.0.2+9-LTS])
  JAVA_HOME             : C:\Program Files\Java\jdk-11.0.2
  Random Testing Seed   : B59907BAF0CE17D1
=======================================

> Task :jar
Building without git revision id.

> Task :javadocJar
Building without git revision id.

> Task :sourcesJar
Building without git revision id.

> Task :namingConventions FAILED
Standard output:

Standard error:
Not all subclasses of LuceneTestCase match the naming convention. Concrete classes must end with [Tests]:
 * org.devmaster.elasticsearch.index.RecurringTest


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':namingConventions'.
> Process 'command 'C:\Program Files\Java\jdk-11.0.2/bin/java'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 24s
31 actionable tasks: 28 executed, 3 up-to-date

Are you reading these error messages? This one says the problem too:

Not all subclasses of LuceneTestCase match the naming convention. Concrete classes must end with [Tests]:
 * org.devmaster.elasticsearch.index.RecurringTest

Thanks, the installer is compiled. now in junit tests. : D
If I have an error here I will be. : D

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.