Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

Commit

Permalink
[#59] Run tests against provisioned Neo4j instance
Browse files Browse the repository at this point in the history
Travis CI now provisions a Neo4j instance for the latest Neo4j
versions.

All classes that require scenarii to run against remote and
embedded instances now extend `GraphIntegrationTestSuite`.

Despite the workaround for travis-ci/travis-ci #5227, OpenJDK 7
turns out be still unstable. For now, this JDK has been removed.
  • Loading branch information
Florent Biville committed Apr 20, 2016
1 parent 67ca9c4 commit 3ceda86
Show file tree
Hide file tree
Showing 17 changed files with 482 additions and 93 deletions.
23 changes: 19 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,39 @@
sudo: false
sudo: required
cache:
directories:
- $HOME/.m2
language: java
install: true
services:
- docker
jdk:
- openjdk7
#- openjdk7
- oraclejdk7
- oraclejdk8
os:
- linux
env:
matrix:
- NEO_VERSION=2.0.5
WITH_DOCKER=false
- NEO_VERSION=2.1.8
WITH_DOCKER=false
- NEO_VERSION=2.2.9
WITH_DOCKER=false
EXTRA_PROFILES=-Pwith-neo4j-io
- NEO_VERSION=2.3.3
WITH_DOCKER=true
EXTRA_PROFILES=-Pwith-neo4j-io
script: "mvn -T4 clean test -Dneo4j.version=${NEO_VERSION} ${EXTRA_PROFILES}"
before_script:
# Workaround for Travis CI buffer overflow with OpenJDK 7
# Details: https://github.com/travis-ci/travis-ci/issues/5227#issuecomment-165131913
- cat /etc/hosts
- echo "$(hostname | cut -c1-63)"
- sudo hostname "$(hostname | cut -c1-63)"
- sed -e "s/^\\(127\\.0\\.0\\.1.*\\)/\\1 $(hostname | cut -c1-63)/" /etc/hosts | sudo tee /etc/hosts
- cat /etc/hosts
# End of workaround
script: build/run.sh
install: true
after_success:
- mvn clean test jacoco:report coveralls:report
- "[ ${TRAVIS_PULL_REQUEST} = 'false' ] && [ ${TRAVIS_BRANCH} = 'master' ] && mvn clean deploy -DskipTests --settings ./deploy-settings.xml"
Expand Down
7 changes: 7 additions & 0 deletions build/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
set -e
if [ "$WITH_DOCKER" = true ] ; then
docker pull neo4j:${NEO_VERSION}
docker run --detach --publish=7474:7474 --volume=$HOME/neo4j/data:/data --env=NEO4J_AUTH=neo4j/j4oen neo4j
fi
mvn -T4 clean test -Dneo4j.version=${NEO_VERSION} ${EXTRA_PROFILES}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.liquigraph.core;

import com.google.common.base.Optional;
import org.junit.rules.ExternalResource;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.test.TestGraphDatabaseFactory;
Expand All @@ -25,9 +26,11 @@
import java.util.Properties;
import java.util.UUID;

import static com.google.common.base.Optional.absent;
import static com.google.common.base.Throwables.propagate;

public class EmbeddedGraphDatabaseRule extends ExternalResource {
public class EmbeddedGraphDatabaseRule extends ExternalResource
implements GraphDatabaseRule {

private final String dbName;
private final String uri;
Expand All @@ -38,15 +41,27 @@ public EmbeddedGraphDatabaseRule(String name) {
dbName = name + "-" + UUID.randomUUID().toString();
uri = "jdbc:neo4j:instance:" + dbName;
}

public Connection jdbcConnection() {

@Override
public Connection connection() {
return connection;
}

@Override
public String uri() {
return uri;
}

@Override
public Optional<String> username() {
return absent();
}

@Override
public Optional<String> password() {
return absent();
}

protected void before() {
try {
db = new TestGraphDatabaseFactory().newImpermanentDatabase();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.liquigraph.core;

import com.google.common.base.Optional;
import org.junit.rules.TestRule;

import java.sql.Connection;

public interface GraphDatabaseRule extends TestRule {

Connection connection();
String uri();
Optional<String> username();
Optional<String> password();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.liquigraph.core;

public interface GraphIntegrationTestSuite {

GraphDatabaseRule graphDatabase();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/**
* Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.liquigraph.core;

import com.google.common.base.Optional;
import org.junit.Assume;
import org.junit.rules.ExternalResource;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import static com.google.common.base.Throwables.propagate;
import static org.assertj.core.api.Assertions.assertThat;

public class RemoteGraphDatabaseRule extends ExternalResource
implements GraphDatabaseRule {

private final String uri;
private final String username;
private final String password;
private Connection connection;

public RemoteGraphDatabaseRule() {
uri = "jdbc:neo4j://127.0.0.1:7474";
username = "neo4j";
password = "j4oen";
}

public static void assumeRemoteGraphDatabaseIsProvisioned() {
Assume.assumeTrue(
"Neo4j remote instance is provisioned with Docker",
"true".equals(System.getenv("WITH_DOCKER"))
);
}

@Override
public Statement apply(Statement base, Description description) {
assumeRemoteGraphDatabaseIsProvisioned();
return super.apply(base, description);
}

@Override
public Connection connection() {
return connection;
}

@Override
public String uri() {
return uri;
}

@Override
public Optional<String> username() {
return Optional.of(username);
}

@Override
public Optional<String> password() {
return Optional.of(password);
}

protected void before() {
try {
Class.forName("org.neo4j.jdbc.Driver");
connection = DriverManager.getConnection(uri, username, password);
connection.setAutoCommit(false);
emptyDatabase(connection);
} catch (ClassNotFoundException | SQLException e) {
throw propagate(e);
}
}

protected void after() {
try {
if (!connection.isClosed()) {
connection.close();
}
} catch (SQLException e) {
throw propagate(e);
}
}

private void emptyDatabase(Connection connection) throws SQLException {
try (java.sql.Statement statement = connection.createStatement()) {
assertThat(statement.execute("MATCH (n) OPTIONAL MATCH (n)-[r]->() DELETE n,r")).isTrue();
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.liquigraph.core.api;

import org.junit.Rule;
import org.liquigraph.core.EmbeddedGraphDatabaseRule;
import org.liquigraph.core.GraphDatabaseRule;

public class LiquigraphEmbeddedTest extends LiquigraphTestSuite {

@Rule
public GraphDatabaseRule graph = new EmbeddedGraphDatabaseRule("neo");

@Override
public GraphDatabaseRule graphDatabase() {
return graph;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.liquigraph.core.api;

import org.junit.Rule;
import org.liquigraph.core.GraphDatabaseRule;
import org.liquigraph.core.RemoteGraphDatabaseRule;

public class LiquigraphRemoteTest extends LiquigraphTestSuite {

@Rule
public GraphDatabaseRule graph = new RemoteGraphDatabaseRule();

@Override
public GraphDatabaseRule graphDatabase() {
return graph;
}
}
Loading

0 comments on commit 3ceda86

Please sign in to comment.