"unable to install test security manager" when using ESTestCase

I am testing my code using ESTestCase. When running the test I get the following error:

java.lang.RuntimeException: unable to install test security manager

	at org.elasticsearch.bootstrap.BootstrapForTesting.<clinit>(BootstrapForTesting.java:168)
	at org.elasticsearch.test.ESTestCase.<clinit>(ESTestCase.java:228)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:348)
	at com.carrotsearch.randomizedtesting.RandomizedRunner$2.run(RandomizedRunner.java:620)
Caused by: java.lang.IllegalStateException: codebase property already set: codebase.elasticsearch-secure-sm -> file:/C:/Users/noel.dinger/.m2/repository/org/elasticsearch/elasticsearch-secure-sm/6.4.0/elasticsearch-secure-sm-6.4.0.jar, cannot set to file:/C:/Users/noel.dinger/.m2/repository/org/elasticsearch/elasticsearch-secure-sm/6.4.0/elasticsearch-secure-sm-6.4.0.jar
	at org.elasticsearch.bootstrap.Security.readPolicy(Security.java:234)
	at org.elasticsearch.bootstrap.BootstrapForTesting.<clinit>(BootstrapForTesting.java:143)
Test ignored.
Exception in thread "Thread-1" java.lang.NoClassDefFoundError: Could not initialize class org.elasticsearch.test.ESTestCase
	at java.lang.Thread.run(Thread.java:748)
	Suppressed: java.lang.IllegalStateException: No context information for thread: Thread[id=12, name=Thread-1, state=RUNNABLE, group=TGRP-ElasticsearchStorageBackendTestNew]. 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:1872)
		at com.carrotsearch.randomizedtesting.RunnerThreadGroup.uncaughtException(RunnerThreadGroup.java:20)
		at java.lang.Thread.dispatchUncaughtException(Thread.java:1959)

Those are my dependencies:

  <dependencies>
    <dependency>
        <groupId>org.elasticsearch.client</groupId>
        <artifactId>elasticsearch-rest-high-level-client</artifactId>
        <version>6.4.0</version>
    </dependency>

    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>${org.apache.logging.log4j.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>${org.apache.logging.log4j.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-slf4j-impl</artifactId>
        <version>${org.apache.logging.log4j.version}</version>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>${org.projectlombok.version}</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.6.2</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.9.6</version>
    </dependency>
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-test-framework</artifactId>
            <version>7.4.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch.test</groupId>
            <artifactId>framework</artifactId>
            <version>6.4.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>21.0</version>
        </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <artifactId>hamcrest-core</artifactId>
                <groupId>org.hamcrest</groupId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

How are you running the test? A similar problem was fixed recently: https://github.com/elastic/elasticsearch/issues/33045

Thanks for your answer. I dont really get what was done in this github post. Which file did he edit?
I use junit in IntelliJ IDEA and for running it I use right Click "Run ...".

import org.elasticsearch.client.Client;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.node.Node;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.ESTestCase;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.io.Files;
import java.io.File;
import java.io.IOException;
import java.util.Optional;
import java.util.UUID;

    public class ElasticsearchStorageBackendTestNew extends ESTestCase {

        private static String index = "clusters";
        private static String docType = "elasticsearch";
        IndexResponse indexResponse;
        private DatabaseCustomerClusterConfig config;
        ElasticsearchStorageBackend elasticsearchStorageBackend;
        DatabaseEceClusterConfig databaseEceClusterConfig;
        String clusterId;
        private static final Logger logger = LoggerFactory.getLogger(ElasticsearchStorageBackendTestNew.class);


        private ElasticsearchStorageBackend createBackend() {
            elasticsearchStorageBackend =  new ElasticsearchStorageBackend("localhost", "9200", "...", "user", "pw", "http");
            return elasticsearchStorageBackend;
        }

        private DatabaseCustomerClusterConfig createClusterConfigValid() {
            UUID clusterID = UUID.randomUUID();
            config = new DatabaseCustomerClusterConfig("d.fiedler@example.com", 5, databaseEceClusterConfig, clusterId, "mySecondCluster", "kibanaid123");
            return config;
        }

        private DatabaseEceClusterConfig createEceConfig(){
            databaseEceClusterConfig = new DatabaseEceClusterConfig("DEV", 1000, 3, 1, "1.0", 1000, 2, 1, "1.11" );
            return databaseEceClusterConfig;
        }


        @Test
        public void testCreateCustomerClusterConfigEntryValid() {
            config = createClusterConfigValid();
            elasticsearchStorageBackend.createCustomerClusterConfigEntry(config, index);
        }

There is no edit to make. This will be fixed in 6.5.0. See this PR: https://github.com/elastic/elasticsearch/pull/33066

Is there any known workaround for 6.4.2 ?

Seeing the same thing in Red Hat JBoss Developer Studio Version: 11.3.0.GA.

Sorry @paulkeogh I don't know of any workarounds for 6.4.x.

@uwieuwe4, @paulkeogh:
A workaround is to disable the security manager during test by adding the following VM option

 -Dtests.security.manager=false

When running your tests with Maven, you can add the following to your pom.xml:

<build>
	<pluginManagement>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-surefire-plugin</artifactId>
				<configuration>
					<!-- for disabling security manager in tests -->
					<systemPropertyVariables>
						<tests.security.manager>false</tests.security.manager>
					</systemPropertyVariables>
				</configuration>
			</plugin>
		</plugins>
	</pluginManagement>
</build>

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