Fixed the embedded Cassandra server by using a newer version, no published artifact so had to include JAR file. Ran Facebook tool called 'infer' which was fairly clean (mvn clean; infer -- mvn package -Dmaven.test.skip=true), two minor potential resource leaks and one possible null pointer dereference

This commit is contained in:
Greg Burd 2017-07-28 11:44:48 -04:00
parent b98f9ed7f5
commit de495ae0eb
8 changed files with 117 additions and 174 deletions

2
.gitignore vendored
View file

@ -1,3 +1,5 @@
infer-out
*.class
# Mobile Tools for Java (J2ME)

View file

@ -35,11 +35,46 @@
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.6" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-core:4.3.10.RELEASE" level="project" />
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:guava:16.0.1" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:guava:22.0" level="project" />
<orderEntry type="library" name="Maven: com.google.code.findbugs:jsr305:1.3.9" level="project" />
<orderEntry type="library" name="Maven: com.google.errorprone:error_prone_annotations:2.0.18" level="project" />
<orderEntry type="library" name="Maven: com.google.j2objc:j2objc-annotations:1.1" level="project" />
<orderEntry type="library" name="Maven: org.codehaus.mojo:animal-sniffer-annotations:1.14" level="project" />
<orderEntry type="library" name="Maven: javax.validation:validation-api:2.0.0.CR3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.codehaus.jackson:jackson-mapper-asl:1.9.13" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: com.anthemengineering.mojo:infer-maven-plugin:0.1.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apache.maven:maven-plugin-api:2.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apache.maven.plugin-tools:maven-plugin-tools-annotations:3.4" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apache.maven:maven-project:2.2.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apache.maven:maven-settings:2.2.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apache.maven:maven-profile:2.2.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apache.maven:maven-artifact-manager:2.2.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apache.maven:maven-repository-metadata:2.2.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apache.maven.wagon:wagon-provider-api:1.0-beta-6" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: backport-util-concurrent:backport-util-concurrent:3.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apache.maven:maven-plugin-registry:2.2.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.codehaus.plexus:plexus-interpolation:1.11" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apache.maven:maven-artifact:2.2.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.codehaus.plexus:plexus-container-default:1.0-alpha-9-stable-1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: classworlds:classworlds:1.1-alpha-2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apache.maven:maven-model:2.2.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apache.maven:maven-plugin-descriptor:2.2.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apache.maven.plugin-tools:maven-plugin-tools-api:3.4" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apache.maven.plugin-tools:maven-plugin-annotations:3.4" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.codehaus.plexus:plexus-utils:3.0.20" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.codehaus.plexus:plexus-component-annotations:1.5.5" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.codehaus.plexus:plexus-archiver:2.1.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.codehaus.plexus:plexus-io:2.0.3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: com.thoughtworks.qdox:qdox:2.0-M3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.codehaus.plexus:plexus-compiler-api:2.5" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apache.commons:commons-compress:1.9" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.tukaani:xz:1.5" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.codehaus.jackson:jackson-core-asl:1.9.13" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.cassandraunit:cassandra-unit:3.1.3.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.cassandraunit:cassandra-unit:3.1.4.0-SNAPSHOT" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apache.thrift:libthrift:0.9.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apache.httpcomponents:httpclient:4.2.5" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apache.httpcomponents:httpcore:4.2.4" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: net.java.dev.jna:jna:4.1.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apache.cassandra:cassandra-all:3.11.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.xerial.snappy:snappy-java:1.1.1.7" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: net.jpountz.lz4:lz4:1.3.0" level="project" />
@ -65,9 +100,8 @@
<orderEntry type="library" scope="TEST" name="Maven: com.lmax:disruptor:3.0.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: com.clearspring.analytics:stream:2.5.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: it.unimi.dsi:fastutil:6.5.7" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apache.thrift:libthrift:0.9.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apache.httpcomponents:httpclient:4.2.5" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apache.httpcomponents:httpcore:4.2.4" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: ch.qos.logback:logback-core:1.1.3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: ch.qos.logback:logback-classic:1.1.3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apache.cassandra:cassandra-thrift:3.11.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: com.carrotsearch:hppc:0.5.4" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: de.jflex:jflex:1.6.0" level="project" />
@ -75,7 +109,6 @@
<orderEntry type="library" scope="TEST" name="Maven: org.apache.ant:ant-launcher:1.7.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: com.github.rholder:snowball-stemmer:1.3.0.581.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: com.googlecode.concurrent-trees:concurrent-trees:2.4.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: net.java.dev.jna:jna:4.4.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: com.github.jbellis:jamm:0.3.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: io.netty:netty-all:4.0.44.Final" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: joda-time:joda-time:2.4" level="project" />

71
pom.xml
View file

@ -21,7 +21,7 @@
</licenses>
<scm>
<url>https://github.net.helenus</url>
<url>https://github.net/onshape/helenus</url>
<connection>scm:git:git@github.com:onshape/helenus.git</connection>
<developerConnection>scm:git:git@github.com:onshape/helenus.git</developerConnection>
</scm>
@ -42,6 +42,14 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>project-repo</id>
<name>project repo</name>
<url>file://${project.basedir}/lib</url>
</repository>
</repositories>
<profiles>
<profile>
@ -66,6 +74,24 @@
</executions>
</plugin>
<plugin>
<groupId>com.anthemengineering.mojo</groupId>
<artifactId>infer-maven-plugin</artifactId>
<version>0.1.0</version>
<configuration>
<consoleOut>false</consoleOut>
</configuration>
<executions>
<execution>
<phase>verify</phase>
<id>infer</id>
<goals>
<goal>infer</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
@ -87,20 +113,6 @@
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>3.3.0</version>
<exclusions>
<exclusion>
<artifactId>slf4j-log4j12</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
<exclusion>
<artifactId>slf4j-log4j12</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
<exclusion>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
@ -130,7 +142,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>16.0.1</version>
<version>22.0</version>
</dependency>
<!-- Validation -->
@ -149,6 +161,13 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.anthemengineering.mojo</groupId>
<artifactId>infer-maven-plugin</artifactId>
<version>0.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
@ -159,7 +178,7 @@
<dependency>
<groupId>org.cassandraunit</groupId>
<artifactId>cassandra-unit</artifactId>
<version>3.1.3.2</version>
<version>3.1.4.0-SNAPSHOT</version>
<scope>test</scope>
<exclusions>
<exclusion>
@ -174,24 +193,6 @@
<artifactId>cassandra-all</artifactId>
<version>3.11.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
</exclusion>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>

View file

@ -15,6 +15,7 @@
*/
package net.helenus.core;
import java.io.IOException;
import java.io.PrintStream;
import java.util.*;
import java.util.concurrent.Executor;
@ -41,7 +42,7 @@ public final class SessionInitializer extends AbstractSessionOperations {
private String usingKeyspace;
private boolean showCql = false;
private PrintStream printStream = System.out;
private Executor executor = MoreExecutors.sameThreadExecutor();
private Executor executor = MoreExecutors.directExecutor();
private SessionRepositoryBuilder sessionRepository;
@ -144,7 +145,7 @@ public final class SessionInitializer extends AbstractSessionOperations {
try {
PackageUtil.getClasses(packageName).stream().filter(c -> c.isInterface() && !c.isAnnotation())
.forEach(initList::add);
} catch (ClassNotFoundException e) {
} catch (IOException | ClassNotFoundException e) {
throw new HelenusException("fail to add package " + packageName, e);
}
return this;

View file

@ -22,6 +22,7 @@ import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import com.datastax.driver.core.*;
@ -51,6 +52,7 @@ public class DslInvocationHandler<E> implements InvocationHandler {
this.entity = new HelenusMappingEntity(iface, metadata);
this.parent = parent;
if (this.entity != null) {
for (HelenusProperty prop : entity.getOrderedProperties()) {
map.put(prop.getGetterMethod(), prop);
@ -81,6 +83,7 @@ public class DslInvocationHandler<E> implements InvocationHandler {
}
}
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

View file

@ -51,7 +51,7 @@ public class PackageUtil {
}
}
public static Set<Class<?>> getClasses(String packagePath) throws ClassNotFoundException {
public static Set<Class<?>> getClasses(String packagePath) throws ClassNotFoundException, IOException {
Set<Class<?>> classes = new HashSet<Class<?>>();
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
if (classLoader == null) {
@ -81,8 +81,8 @@ public class PackageUtil {
if (!"".equals(rootEntry) && !rootEntry.endsWith("/")) {
rootEntry = rootEntry + "/";
}
try {
JarFile jarFile = null;
try {
URLConnection con = url.openConnection();
if (con instanceof JarURLConnection) {
JarURLConnection jarCon = (JarURLConnection) con;
@ -107,6 +107,9 @@ public class PackageUtil {
}
} catch (IOException e) {
throw new ClassNotFoundException("jar fail", e);
} finally {
if (jarFile != null)
jarFile.close();
}
}
}

View file

@ -26,6 +26,7 @@ import com.datastax.driver.core.KeyspaceMetadata;
import com.datastax.driver.core.Session;
import java.io.IOException;
import java.util.UUID;
/**
* AbstractEmbeddedCassandraTest
@ -37,7 +38,7 @@ public abstract class AbstractEmbeddedCassandraTest {
private static Cluster cluster;
private static String keyspace = BuildProperties.getRandomKeyspace();
private static String keyspace;
private static Session session;
@ -64,14 +65,13 @@ public abstract class AbstractEmbeddedCassandraTest {
}
@BeforeClass
public static void before() throws TTransportException, IOException, InterruptedException, ConfigurationException {
//EmbeddedCassandraServerHelper.startEmbeddedCassandra(BuildProperties.getCassandraConfig());
public static void startCassandraEmbeddedServer() throws TTransportException, IOException, InterruptedException, ConfigurationException {
keyspace = "test" + UUID.randomUUID().toString().replace("-", "");
EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.CASSANDRA_RNDPORT_YML_FILE);
cluster = Cluster.builder()
.addContactPoint("localhost")
//.addContactPoint(BuildProperties.getCassandraHost())
.withPort(9042)
//.withPort(BuildProperties.getCassandraNativePort())
.addContactPoint(EmbeddedCassandraServerHelper.getHost())
.withPort(EmbeddedCassandraServerHelper.getNativeTransportPort())
.build();
KeyspaceMetadata kmd = cluster.getMetadata().getKeyspace(keyspace);
@ -95,13 +95,9 @@ public abstract class AbstractEmbeddedCassandraTest {
@AfterClass
public static void after() {
if (!keep && isConnected()) {
String cql = "DROP " + keyspace + ";";
System.out.println(cql + "\n");
// session.execute(cql);
session.close();
session = null;
// EmbeddedCassandraServerHelper.cleanEmbeddedCassandra();
EmbeddedCassandraServerHelper.cleanEmbeddedCassandra();
}
}
}

View file

@ -1,96 +0,0 @@
/*
* Copyright (C) 2015 The Helenus 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 net.helenus.test.integration.build;
import java.io.InputStream;
import java.util.Properties;
import java.util.UUID;
import org.apache.commons.io.IOUtils;
public final class BuildProperties {
private final static class Singleton {
private final static BuildProperties INSTANCE = new BuildProperties();
}
private final String cassandraConfig;
private final Properties props = new Properties();
private BuildProperties() {
if (false) { //isRunInMaven()) {
this.cassandraConfig = "build-cassandra.yaml";
loadFromClasspath("build.properties");
}
else {
this.cassandraConfig = "eclipse-cassandra.yaml";
loadFromClasspath("eclipse.properties");
}
}
private boolean isRunInMaven() {
return System.getProperty("maven.integration.test") != null;
}
private void loadFromClasspath(String resourceName) {
InputStream in = getClass().getResourceAsStream("/" + resourceName);
if (in == null) {
throw new RuntimeException("resource is not found in classpath: " + resourceName);
}
try {
props.load(in);
} catch (Exception x) {
throw new RuntimeException(x);
} finally {
IOUtils.closeQuietly(in);
}
}
public static String getCassandraConfig() {
return Singleton.INSTANCE.cassandraConfig;
}
public static String getCassandraHost() {
return "localhost";
}
public static String getRandomKeyspace() {
return "test" + UUID.randomUUID().toString().replace("-", "");
}
public static int getCassandraNativePort() {
return Singleton.INSTANCE.getInt("build.cassandra.native_transport_port");
}
public static int getCassandraRpcPort() {
return Singleton.INSTANCE.getInt("build.cassandra.rpc_port");
}
public static int getCassandraStoragePort() {
return Singleton.INSTANCE.getInt("build.cassandra.storage_port");
}
public static int getCassandraSslStoragePort() {
return Singleton.INSTANCE.getInt("build.cassandra.ssl_storage_port");
}
private int getInt(String key) {
return Integer.parseInt(props.getProperty(key));
}
}