Skip to content

Commit

Permalink
Set up Travis-CI #176
Browse files Browse the repository at this point in the history
  • Loading branch information
sai-pullabhotla committed Sep 23, 2017
1 parent 850f20b commit d331865
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
language: java
dist: trusty
26 changes: 26 additions & 0 deletions src/test/java/com/jmethods/catatumbo/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.google.cloud.datastore.Datastore;
import com.google.cloud.datastore.DatastoreOptions;
import com.google.cloud.datastore.testing.LocalDatastoreHelper;
import com.google.cloud.http.HttpTransportOptions;
import com.jmethods.catatumbo.impl.DefaultEntityManager;

Expand All @@ -37,8 +38,29 @@ public class TestUtils {
public static final String ENV_CREDENTIALS = ENV_PREFIX + "CREDENTIALS";
public static final String ENV_CONNECTION_TIMEOUT = ENV_PREFIX + "CONNECTION_TIMEOUT";
public static final String ENV_READ_TIMEOUT = ENV_PREFIX + "READ_TIMEOUT";
public static boolean isCI;
private static DatastoreOptions options;

static {
String ci = System.getenv("CI");
isCI = Boolean.parseBoolean(ci);

if (isCI) {
LocalDatastoreHelper helper = LocalDatastoreHelper.create(1.0);
try {
helper.start();
} catch (Throwable t) {
t.printStackTrace();
throw new RuntimeException("Failed to start Datastore Emulator");
}
options = helper.getOptions();
}
}

public static EntityManager getEntityManager() throws FileNotFoundException {
if (isCI) {
return getCIEntityManager();
}
ConnectionParameters parameters = new ConnectionParameters();
parameters.setServiceURL(System.getenv(ENV_SERVICE_URL));
parameters.setProjectId(System.getenv(ENV_PROJECT_ID));
Expand Down Expand Up @@ -73,6 +95,10 @@ public static EntityManager getEntityManager() throws FileNotFoundException {

}

public static EntityManager getCIEntityManager() {
return EntityManagerFactory.getInstance().createLocalEntityManager(options.getHost(), options.getProjectId());
}

public static String getRandomString(int length) {
Random random = new Random();
StringBuilder buffer = new StringBuilder(length);
Expand Down

0 comments on commit d331865

Please sign in to comment.