Skip to content

Commit

Permalink
don’t try to load default settings for the client from elasticsearch …
Browse files Browse the repository at this point in the history
…config

files and removed loadConfigSettings parameter from client constructor

client tests now use crate-testing, so the client tests run agains a seperate
jvm which reflects the real world scenario
  • Loading branch information
dobe committed Feb 16, 2016
1 parent c7fb683 commit a38447c
Show file tree
Hide file tree
Showing 11 changed files with 192 additions and 158 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Changes for Crate
Unreleased
==========

- removed wrong behaving CrateClient feature which allowed to load
client settings from a configuration file.

- Implemented the EXPLAIN command for SELECT statements.

- BREAKING CHANGE: Tables are not refreshed automatically anymore
Expand Down
13 changes: 7 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ evaluationDependsOn(':sql')
evaluationDependsOn(':sql-parser')
evaluationDependsOn(':blob')
evaluationDependsOn(':udc')
evaluationDependsOn(':client')
evaluationDependsOn(':dns-discovery')
evaluationDependsOn(':aws')

Expand All @@ -44,7 +43,6 @@ dependencies {
compile project(':admin-ui')
compile project(':blob')
compile project(':udc')
compile project(':client')
compile project(':dns-discovery')
compile project(':aws')

Expand All @@ -61,7 +59,6 @@ dependencies {
compileNotTransitive project(':admin-ui')
compileNotTransitive project(':blob')
compileNotTransitive project(':udc')
compileNotTransitive project(':client')
compileNotTransitive project(':dns-discovery')
}

Expand Down Expand Up @@ -123,7 +120,12 @@ task dist {

task myJavadocs(type: Javadoc, dependsOn: processResources) {
classpath = configurations.compile
source = sourceSets.main.allJava + project(':core').sourceSets.main.allJava + project(':sql').sourceSets.main.allJava + project(':sql-parser').sourceSets.main.allJava + project(':blob').sourceSets.main.allJava + project(':udc').sourceSets.main.allJava + project(':client').sourceSets.main.allJava
source = sourceSets.main.allJava +
project(':core').sourceSets.main.allJava +
project(':sql').sourceSets.main.allJava +
project(':sql-parser').sourceSets.main.allJava +
project(':blob').sourceSets.main.allJava +
project(':udc').sourceSets.main.allJava
}

task javadocJar (type: Jar, dependsOn: [myJavadocs]) {
Expand All @@ -147,8 +149,7 @@ task sourceJar (type : Jar) {
project(':sql').sourceSets.main.allJava +
project(':sql-parser').sourceSets.main.allJava +
project(':blob').sourceSets.main.allJava +
project(':udc').sourceSets.main.allJava +
project(':client').sourceSets.main.allJava)
project(':udc').sourceSets.main.allJava)
manifest {
attributes("Implementation-Title": "Crate.IO")
}
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ subprojects {



def jvmTestFlags = ['-ea']
def jvmTestFlags = ['-ea', "-Dproject_build_dir=$project.buildDir", '-Dproject_root=$PROJECT_DIR$']

idea {
workspace {
Expand Down
96 changes: 61 additions & 35 deletions client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,41 @@ plugins {
id 'com.github.johnrengelman.shadow' version '1.2.3'
}

repositories {
jcenter()
}

archivesBaseName = "crate-client"

evaluationDependsOn(':core')
evaluationDependsOn(':sql')
evaluationDependsOn(':app')

configurations {
all*.exclude group: 'org.elasticsearch'
}

def coreIncludes = ['io/crate/Streamer*',
"io/crate/TimestampFormat*",
"io/crate/core/collections/MapComparator*",
"io/crate/core/collections/ForEach*",
"io/crate/core/StringUtils*",
"io/crate/geo/GeoJSONUtils*",
"io/crate/types/**"]

def sqlIncludes = ["io/crate/action/sql/SQL*"]

task depClasses(type: Copy, dependsOn: [':core:compileJava', ':sql:compileJava']) {
duplicatesStrategy 'fail'
from(project(':core').sourceSets.main.output) {
include coreIncludes
}
from(project(':sql').sourceSets.main.output) {
include sqlIncludes
}
into file('build/deps/')
}

dependencies {
compile (project(':es')) {
compile(project(':es')) {
exclude group: 'org.apache.lucene'
exclude group: 'org.codehaus.groovy'
exclude group: 'com.github.spullara.mustache.java'
Expand All @@ -25,26 +49,26 @@ dependencies {
exclude group: 'commons-cli'
exclude group: 'org.slf4j'
}
// needed by ES Version class - keep up to date with es dependencies
// required by ES and Lucene Version classes - keep up to date with es dependencies
// The version module is required by the DiscoveryNode module
compile 'org.apache.lucene:lucene-core:4.10.4'
compile 'org.apache.lucene:lucene-analyzers-common:4.10.4'

compile 'com.google.code.findbugs:annotations:3.0.0'
compile files(project(':core').sourceSets.shared.output.classesDir)
compile files(project(':sql').sourceSets.shared.output.classesDir)
compile files(depClasses)
testCompile 'io.crate:crate-testing:0.3.1'
testCompile 'org.hamcrest:hamcrest-all:1.3'

testCompile project(':testing')
testCompile project(':core')
testCompile project(':sql')
}

processResources.dependsOn([':core:compileSharedJava', ':sql:compileSharedJava'])
compileJava.dependsOn([':core:compileSharedJava', ':sql:compileSharedJava'])

compileTestJava {
dependsOn ':app:distTar'
}

test {
systemProperty 'project_root', rootProject.projectDir
systemProperty 'project_build_dir', rootProject.buildDir
dependsOn ':app:distTar'
testLogging.exceptionFormat = 'full'

jacoco {
excludes = [ "*Test*" ]
}
Expand All @@ -54,25 +78,25 @@ shadowJar {

baseName 'crate-client'
classifier ''
duplicatesStrategy 'exclude'
duplicatesStrategy 'fail'

exclude 'org/hyperic/**' // exclude sigar stuff
exclude 'META-INF/**'

// remember to update mapping in CrateClientClassLoader when changing this
relocate 'org.elasticsearch', 'io.crate.shade.org.elasticsearch'
relocate 'org.apache.lucene', 'io.crate.shade.org.apache.lucene'
relocate 'org.joda', 'io.crate.shade.org.joda'
relocate 'org.elasticsearch', 'io.crate.shade.org.elasticsearch'
relocate 'org.apache.lucene', 'io.crate.shade.org.apache.lucene'
relocate 'org.joda', 'io.crate.shade.org.joda'
relocate 'org.tartarus.snowball', 'io.crate.shade.org.tartarus.snowball'
relocate 'com.carrotsearch.hppc', 'io.crate.shade.com.carrotsearch.hppc'
relocate 'com.fasterxml.jackson', 'io.crate.shade.com.fasterxml.jackson'
relocate 'com.google', 'io.crate.shade.com.google'
relocate 'com.ning.compress', 'io.crate.shade.com.ning.compress'
relocate 'org.jboss.netty', 'io.crate.shade.org.jboss.netty'
relocate 'org.apache.commons', 'io.crate.shade.org.apache.commons'
relocate 'jsr166e', 'io.crate.shade.jsr166e'
relocate 'com.spatial4j', 'io.crate.shade.com.spatial4j'
relocate 'com.vividsolutions', 'io.crate.shade.com.vividsolutions'
relocate 'com.google', 'io.crate.shade.com.google'
relocate 'com.ning.compress', 'io.crate.shade.com.ning.compress'
relocate 'org.jboss.netty', 'io.crate.shade.org.jboss.netty'
relocate 'org.apache.commons', 'io.crate.shade.org.apache.commons'
relocate 'jsr166e', 'io.crate.shade.jsr166e'
relocate 'com.spatial4j', 'io.crate.shade.com.spatial4j'
relocate 'com.vividsolutions', 'io.crate.shade.com.vividsolutions'

doLast {
manifest {
Expand All @@ -82,7 +106,8 @@ shadowJar {
}
}

task buildJar(dependsOn: [':core:getVersion', ':core:compileSharedJava', ':sql:compileSharedJava', 'classes']) {

task buildJar(dependsOn: [':core:getVersion', 'classes']) {
doLast {
ext.version = project(':core').getVersion.version
project.version = ext.version
Expand All @@ -91,9 +116,17 @@ task buildJar(dependsOn: [':core:getVersion', ':core:compileSharedJava', ':sql:c
}
tasks.buildJar.mustRunAfter jar // otherwise jar task would override shadowJar artifact

task sourceJar (type : Jar) {
classifier = 'sources'
from sourceSets.main.java
manifest {
attributes("Implementation-Title": "Crate.IO Java Client")
}
}

task myJavadocs(type: Javadoc, dependsOn: processResources) {
classpath = configurations.compile
source = sourceSets.main.allJava + project(':core').sourceSets.shared.allJava + project(':sql').sourceSets.shared.allJava
source = sourceSets.main.java //compileJava.source
}
task javadocJar (type: Jar, dependsOn: [myJavadocs]) {
classifier = 'javadoc'
Expand All @@ -109,13 +142,6 @@ task buildJavadocJar (dependsOn: [':core:getVersion', myJavadocs] ) << {
tasks.javadocJar.execute()
}

task sourceJar (type : Jar) {
classifier = 'sources'
from sourceSets.main.allSource + project(':core').sourceSets.shared.allSource + project(':sql').sourceSets.shared.allSource
manifest {
attributes("Implementation-Title": "Crate.IO Java Client")
}
}

task buildSourceJar (dependsOn: [':core:getVersion'] ) << {
ext.version = project(':core').getVersion.version
Expand Down Expand Up @@ -148,7 +174,7 @@ install {
project.ext.bintrayUsername = project.hasProperty('bintrayUsername') ? bintrayUsername : ""
project.ext.bintrayPassword = project.hasProperty('bintrayPassword') ? bintrayPassword : ""

uploadArchives.dependsOn([':core:compileSharedJava', ':sql:compileSharedJava', buildJavadocJar, buildSourceJar, buildJar, signJars])
uploadArchives.dependsOn([install, signJars])
uploadArchives {
repositories{
mavenDeployer {
Expand Down
12 changes: 5 additions & 7 deletions client/src/main/java/io/crate/client/CrateClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class CrateClient {
private static final ESLogger logger = Loggers.getLogger(CrateClient.class);


public CrateClient(Settings pSettings, boolean loadConfigSettings, String ... servers) throws
public CrateClient(Settings pSettings, String ... servers) throws
ElasticsearchException {

Settings settings = settingsBuilder()
Expand All @@ -84,21 +84,19 @@ public CrateClient(Settings pSettings, boolean loadConfigSettings, String ... se
.put("threadpool.get.size", 1)
.put("threadpool.percolate.size", 1)
.build();
Tuple<Settings, Environment> tuple = InternalSettingsPreparer.prepareSettings(
settings, loadConfigSettings);
Tuple<Settings, Environment> tuple = InternalSettingsPreparer.prepareSettings(settings, false);

// override classloader
CrateClientClassLoader clientClassLoader = new CrateClientClassLoader(tuple.v1().getClassLoader());
this.settings = ImmutableSettings.builder().put(tuple.v1()).classLoader(clientClassLoader).build();
Version version = Version.CURRENT;

CompressorFactory.configure(this.settings);

threadPool = new ThreadPool(this.settings);

ModulesBuilder modules = new ModulesBuilder();
modules.add(new CrateClientModule());
modules.add(new Version.Module(version));
modules.add(new Version.Module(Version.CURRENT));
modules.add(new ThreadPoolModule(threadPool));

modules.add(new SettingsModule(this.settings));
Expand All @@ -120,11 +118,11 @@ public CrateClient(Settings pSettings, boolean loadConfigSettings, String ... se
}

public CrateClient() {
this(ImmutableSettings.Builder.EMPTY_SETTINGS, true);
this(ImmutableSettings.Builder.EMPTY_SETTINGS);
}

public CrateClient(String... servers) {
this(ImmutableSettings.EMPTY, true, servers);
this(ImmutableSettings.EMPTY, servers);
}

@Nullable
Expand Down
57 changes: 4 additions & 53 deletions client/src/test/java/io/crate/client/CrateClientCreationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,53 +22,22 @@

package io.crate.client;

import io.crate.plugin.CrateCorePlugin;
import org.elasticsearch.client.transport.TransportClientNodesService;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.test.ElasticsearchIntegrationTest;
import org.elasticsearch.transport.TransportService;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.lang.reflect.Field;
import java.net.InetSocketAddress;
import java.util.List;
import java.util.Locale;

import static org.hamcrest.CoreMatchers.startsWith;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.core.Is.is;

public class CrateClientCreationTest extends ElasticsearchIntegrationTest {

private int port;
private String serverAddress;

private static final String TEST_SETTINGS_PATH = CrateClientCreationTest.class.getResource("crate.yml").getPath();

@Override
protected Settings nodeSettings(int nodeOrdinal) {
return ImmutableSettings.settingsBuilder()
.put(super.nodeSettings(nodeOrdinal))
.put("node.mode", "network")
.put("plugin.types", CrateCorePlugin.class.getName())
.build();
}

@Before
public void prepare() {
System.setProperty("es.config", TEST_SETTINGS_PATH);
InetSocketAddress address = ((InetSocketTransportAddress) internalCluster()
.getInstance(TransportService.class)
.boundAddress().boundAddress()).address();
port = address.getPort();
serverAddress = String.format(Locale.ENGLISH, "localhost:%s", port);
}
public class CrateClientCreationTest extends CrateClientIntegrationTest {

@After
public void cleanUp() throws Exception {
Expand All @@ -87,7 +56,7 @@ public void testNoDefaultNodes() throws Exception {

@Test
public void testWithNode() throws Exception {
CrateClient localClient = new CrateClient(ImmutableSettings.EMPTY, false, serverAddress);
CrateClient localClient = new CrateClient(ImmutableSettings.EMPTY, serverAddress());
try {
assertThat(extractDiscoveryNodes(localClient), hasSize(1));
} finally {
Expand All @@ -107,7 +76,7 @@ private List<DiscoveryNode> extractDiscoveryNodes(CrateClient crateClient) throw

@Test
public void testCreateWithServer() throws Exception {
CrateClient localClient = new CrateClient(ImmutableSettings.EMPTY, false, serverAddress);
CrateClient localClient = new CrateClient(ImmutableSettings.EMPTY, serverAddress());
try {
assertThat(extractDiscoveryNodes(localClient), hasSize(1));
} finally {
Expand Down Expand Up @@ -138,7 +107,7 @@ public void testWithSettings() throws Exception {
CrateClient localClient = new CrateClient(ImmutableSettings.builder()
.put("fancy.setting", "check") // will not be overridden
.put("node.name", "fancy-node-name") // will be overridden
.build(), false);
.build());

try {
Settings settings = localClient.settings();
Expand All @@ -148,22 +117,4 @@ public void testWithSettings() throws Exception {
localClient.close();
}
}

@Test
public void testLoadFromConfig() throws Exception {
CrateClient configClient = new CrateClient(ImmutableSettings.EMPTY, true);
CrateClient noConfigClient = new CrateClient(ImmutableSettings.EMPTY, false);
try {
Settings configSettings = configClient.settings();
Settings noConfigSettings = noConfigClient.settings();

assertThat(configSettings.getAsBoolean("loaded.from.file", false), is(true));
assertThat(noConfigSettings.getAsMap().containsKey("loaded.from.file"), is(false));
} finally {
configClient.close();
noConfigClient.close();
}


}
}
Loading

0 comments on commit a38447c

Please sign in to comment.