Skip to content

Commit

Permalink
[CALCITE-3601] Update elasticsearch tests upgrade from junit4 to juni…
Browse files Browse the repository at this point in the history
…t5 (Qianjin Xu)

closes apache#1681
  • Loading branch information
XuQianJin-Stars authored and vlsi committed Dec 26, 2019
1 parent e50f533 commit 4415171
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 47 deletions.
2 changes: 0 additions & 2 deletions elasticsearch/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,3 @@
#
description=Elasticsearch adapter for Calcite
artifact.name=Calcite Elasticsearch
# JUnit4 use is allowed until the rest of the tests are migrated to JUnit5
junit4=true
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.ImmutableMap;

import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import java.sql.Connection;
import java.sql.DriverManager;
Expand All @@ -47,14 +47,13 @@
*/
public class AggregationTest {

@ClassRule
@RegisterExtension
public static final EmbeddedElasticsearchPolicy NODE = EmbeddedElasticsearchPolicy.create();

private static final String NAME = "aggs";

@BeforeClass
@BeforeAll
public static void setupInstance() throws Exception {

final Map<String, String> mappings = ImmutableMap.<String, String>builder()
.put("cat1", "keyword")
.put("cat2", "keyword")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.ImmutableMap;

import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import java.sql.Connection;
import java.sql.DriverManager;
Expand All @@ -42,7 +42,7 @@
*/
public class BooleanLogicTest {

@ClassRule
@RegisterExtension
public static final EmbeddedElasticsearchPolicy NODE = EmbeddedElasticsearchPolicy.create();

private static final String NAME = "docs";
Expand All @@ -51,7 +51,7 @@ public class BooleanLogicTest {
* Used to create {@code zips} index and insert some data
* @throws Exception when ES node setup failed
*/
@BeforeClass
@BeforeAll
public static void setupInstance() throws Exception {

final Map<String, String> mapping = ImmutableMap.of("a", "keyword", "b", "keyword",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
import com.google.common.io.LineProcessor;
import com.google.common.io.Resources;

import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
Expand All @@ -55,7 +55,7 @@
*/
public class ElasticSearchAdapterTest {

@ClassRule //init once for all tests
@RegisterExtension //init once for all tests
public static final EmbeddedElasticsearchPolicy NODE = EmbeddedElasticsearchPolicy.create();

/** Default index/type name */
Expand All @@ -66,7 +66,7 @@ public class ElasticSearchAdapterTest {
* Used to create {@code zips} index and insert zip data in bulk.
* @throws Exception when instance setup failed
*/
@BeforeClass
@BeforeAll
public static void setupInstance() throws Exception {
final Map<String, String> mapping = ImmutableMap.of("city", "keyword", "state",
"keyword", "pop", "long");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
import org.elasticsearch.client.Request;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.common.transport.TransportAddress;
import org.junit.rules.ExternalResource;
import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;

import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -60,9 +62,8 @@
* }
* }
* </pre>
* @see ExternalResource
*/
class EmbeddedElasticsearchPolicy extends ExternalResource {
class EmbeddedElasticsearchPolicy implements BeforeAllCallback, AfterAllCallback {

private final EmbeddedElasticsearchNode node;
private final ObjectMapper mapper;
Expand All @@ -76,11 +77,11 @@ private EmbeddedElasticsearchPolicy(EmbeddedElasticsearchNode resource) {
closer.add(node);
}

@Override protected void before() throws Throwable {
@Override public void beforeAll(ExtensionContext context) {
node.start();
}

@Override protected void after() {
@Override public void afterAll(ExtensionContext context) throws Exception {
closer.close();
}

Expand Down Expand Up @@ -215,5 +216,4 @@ HttpHost httpHost() {
private TransportAddress httpAddress() {
return node.httpAddress();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
import com.google.common.io.LineProcessor;
import com.google.common.io.Resources;

import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
Expand All @@ -63,13 +63,14 @@
import static org.apache.calcite.test.Matchers.hasTree;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;

/**
* Testing Elasticsearch match query.
*/
public class MatchTest {

@ClassRule //init once for all tests
@RegisterExtension //init once for all tests
public static final EmbeddedElasticsearchPolicy NODE = EmbeddedElasticsearchPolicy.create();

/** Default index/type name */
Expand All @@ -80,7 +81,7 @@ public class MatchTest {
* Used to create {@code zips} index and insert zip data in bulk.
* @throws Exception when instance setup failed
*/
@BeforeClass
@BeforeAll
public static void setup() throws Exception {
final Map<String, String> mapping = ImmutableMap.of("city", "text", "state",
"keyword", "pop", "long");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.ImmutableMap;

import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import java.sql.Connection;
import java.sql.DriverManager;
Expand All @@ -42,20 +42,21 @@
import java.util.function.Consumer;
import java.util.regex.PatternSyntaxException;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;


/**
* Checks renaming of fields (also upper, lower cases) during projections
*/
public class Projection2Test {

@ClassRule
@RegisterExtension
public static final EmbeddedElasticsearchPolicy NODE = EmbeddedElasticsearchPolicy.create();

private static final String NAME = "nested";

@BeforeClass
@BeforeAll
public static void setupInstance() throws Exception {

final Map<String, String> mappings = ImmutableMap.of("a", "long",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.ImmutableMap;

import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import java.sql.Connection;
import java.sql.DriverManager;
Expand All @@ -42,12 +42,12 @@
*/
public class ProjectionTest {

@ClassRule
@RegisterExtension
public static final EmbeddedElasticsearchPolicy NODE = EmbeddedElasticsearchPolicy.create();

private static final String NAME = "docs";

@BeforeClass
@BeforeAll
public static void setupInstance() throws Exception {

final Map<String, String> mappings = ImmutableMap.of("A", "keyword",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -47,13 +47,13 @@
*/
public class ScrollingTest {

@ClassRule
@RegisterExtension
public static final EmbeddedElasticsearchPolicy NODE = EmbeddedElasticsearchPolicy.create();

private static final String NAME = "scroll";
private static final int SIZE = 10;

@BeforeClass
@BeforeAll
public static void setupInstance() throws Exception {
NODE.createIndex(NAME, Collections.singletonMap("value", "long"));
final List<ObjectNode> docs = new ArrayList<>();
Expand Down

0 comments on commit 4415171

Please sign in to comment.