Skip to content

Commit

Permalink
Merge pull request #13 from diegopacheco/dev
Browse files Browse the repository at this point in the history
Added 32 Unit Tests for Dynomite Manager
  • Loading branch information
ipapapa committed Jul 19, 2016
2 parents 46e44c1 + ab336ff commit 0fd0eb0
Show file tree
Hide file tree
Showing 21 changed files with 1,008 additions and 17 deletions.
13 changes: 12 additions & 1 deletion build.gradle
Expand Up @@ -23,6 +23,17 @@ subprojects {
apply plugin: 'nebula.provided-base'
apply plugin: 'nebula.dependency-lock'

test {
testLogging {
events "passed", "skipped", "failed", "standardOut", "standardError"
afterSuite { desc, result ->
if (!desc.parent) { // will match the outermost suite
println "Results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} successes, ${result.failedTestCount} failures, ${result.skippedTestCount} skipped)"
}
}
}
}

group = 'com.netflix.dynomite-manager'

repositories {
Expand Down Expand Up @@ -81,5 +92,5 @@ subprojects {

}


}

10 changes: 5 additions & 5 deletions buildViaTravis.sh
Expand Up @@ -3,21 +3,21 @@

if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
echo -e "Build Pull Request #$TRAVIS_PULL_REQUEST => Branch [$TRAVIS_BRANCH]"
./gradlew build --stacktrace
./gradlew cleanTest build --stacktrace
elif [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_TAG" == "" ]; then
echo -e 'Build Branch with Snapshot => Branch ['$TRAVIS_BRANCH']'
./gradlew -Prelease.travisci=true -PbintrayUser="${bintrayUser}" -PbintrayKey="${bintrayKey}" -PsonatypeUsername="${sonatypeUsername}" -PsonatypePassword="${sonatypePassword}" build snapshot --stacktrace
./gradlew -Prelease.travisci=true -PbintrayUser="${bintrayUser}" -PbintrayKey="${bintrayKey}" -PsonatypeUsername="${sonatypeUsername}" -PsonatypePassword="${sonatypePassword}" cleanTest build snapshot --stacktrace
elif [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_TAG" != "" ]; then
echo -e 'Build Branch for Release => Branch ['$TRAVIS_BRANCH'] Tag ['$TRAVIS_TAG']'
case "$TRAVIS_TAG" in
*-rc\.*)
./gradlew -Prelease.travisci=true -Prelease.useLastTag=true -PbintrayUser="${bintrayUser}" -PbintrayKey="${bintrayKey}" -PsonatypeUsername="${sonatypeUsername}" -PsonatypePassword="${sonatypePassword}" candidate --stacktrace
./gradlew -Prelease.travisci=true -Prelease.useLastTag=true -PbintrayUser="${bintrayUser}" -PbintrayKey="${bintrayKey}" -PsonatypeUsername="${sonatypeUsername}" -PsonatypePassword="${sonatypePassword}" cleanTest candidate --stacktrace
;;
*)
./gradlew -Prelease.travisci=true -Prelease.useLastTag=true -PbintrayUser="${bintrayUser}" -PbintrayKey="${bintrayKey}" -PsonatypeUsername="${sonatypeUsername}" -PsonatypePassword="${sonatypePassword}" final --stacktrace
./gradlew -Prelease.travisci=true -Prelease.useLastTag=true -PbintrayUser="${bintrayUser}" -PbintrayKey="${bintrayKey}" -PsonatypeUsername="${sonatypeUsername}" -PsonatypePassword="${sonatypePassword}" cleanTest final --stacktrace
;;
esac
else
echo -e 'WARN: Should not be here => Branch ['$TRAVIS_BRANCH'] Tag ['$TRAVIS_TAG'] Pull Request ['$TRAVIS_PULL_REQUEST']'
./gradlew build --stacktrace
./gradlew cleanTest build --stacktrace
fi
3 changes: 1 addition & 2 deletions dynomitemanager/build.gradle
@@ -1,2 +1 @@
apply plugin: 'nebula.test-jar'

apply plugin: 'nebula.test-jar'
Expand Up @@ -38,6 +38,8 @@
import com.netflix.dynomitemanager.identity.DefaultVpcInstanceEnvIdentity;
import com.netflix.dynomitemanager.identity.IAppsInstanceFactory;
import com.netflix.dynomitemanager.identity.InstanceEnvIdentity;
import com.netflix.dynomitemanager.monitoring.JedisFactory;
import com.netflix.dynomitemanager.monitoring.SimpleJedisFactory;
import com.netflix.dynomitemanager.sidecore.IConfiguration;
import com.netflix.dynomitemanager.sidecore.ICredential;
import com.netflix.dynomitemanager.sidecore.aws.IAMCredential;
Expand Down Expand Up @@ -130,6 +132,8 @@ protected void configure()

// binder().bind(GuiceContainer.class).asEagerSingleton();
// binder().bind(GuiceJobFactory.class).asEagerSingleton();

binder().bind(JedisFactory.class).to(SimpleJedisFactory.class);

}
}
Expand Down
@@ -0,0 +1,13 @@
package com.netflix.dynomitemanager.monitoring;

import redis.clients.jedis.Jedis;

/**
* Jedis factory to provide a fresh Jedis connection all the time.
*
* @author diegopacheco
*
*/
public interface JedisFactory {
public Jedis newInstance();
}
Expand Up @@ -58,20 +58,22 @@ public class RedisInfoMetricsTask extends Task {
private final ConcurrentHashMap<String, LongGauge> redisInfoGaugeMetrics = new ConcurrentHashMap<String, LongGauge>();
private final ConcurrentHashMap<String, NumericMonitor<Number>> redisInfoCounterMap = new ConcurrentHashMap<String, NumericMonitor<Number>>();

private JedisFactory jedisFactory;

/**
* Default constructor
* @param config
*/
@Inject
public RedisInfoMetricsTask(IConfiguration config) {
public RedisInfoMetricsTask(IConfiguration config,JedisFactory jedisFactory) {
super(config);
this.jedisFactory = jedisFactory;
}

@Override
public void execute() throws Exception {

Jedis jedis = new Jedis("localhost", 22122);
Jedis jedis = jedisFactory.newInstance();
try {
jedis.connect();
String s = jedis.info();
Expand Down
@@ -0,0 +1,20 @@
package com.netflix.dynomitemanager.monitoring;

import redis.clients.jedis.Jedis;

/**
* SimpleJedisFactory create a redis connection with jedis.
*
* @author diegopacheco
*
*/
public class SimpleJedisFactory implements JedisFactory{

public SimpleJedisFactory() {}

@Override
public Jedis newInstance() {
return new Jedis("localhost", 22122);
}

}
Expand Up @@ -25,20 +25,26 @@ public class FifoQueue<E extends Comparable<E>> extends TreeSet<E>

public FifoQueue(int capacity)
{
super(new Comparator<E>()
super(new Comparator<E>()
{
@Override
public int compare(E o1, E o2)
{
return o1.compareTo(o2);
}
});
validateCapacity(capacity);
this.capacity = capacity;
}

private void validateCapacity(int capacity){
if (capacity <=0 ) throw new IllegalArgumentException("Capacity must be >= 1");
}

public FifoQueue(int capacity, Comparator<E> comparator)
{
super(comparator);
validateCapacity(capacity);
this.capacity = capacity;
}

Expand Down
Expand Up @@ -18,18 +18,15 @@
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.netflix.dynomitemanager.InstanceState;
import com.netflix.dynomitemanager.sidecore.storage.IStorageProxy;

@Singleton
public class FloridaHealthCheckHandler implements com.netflix.karyon.spi.HealthCheckHandler {

private InstanceState state;
private final IStorageProxy storageProxy;

@Inject
public FloridaHealthCheckHandler(InstanceState ss, IStorageProxy storageProxy) {
public FloridaHealthCheckHandler(InstanceState ss) {
this.state = ss;
this.storageProxy = storageProxy;
}

@Override
Expand Down
Expand Up @@ -37,6 +37,8 @@ public RetryableCallable()

public RetryableCallable(int retrys, long waitTime)
{
if(retrys<=-1) throw new RuntimeException(new IllegalAccessException("Retrys should be >= 0"));
if(waitTime<=-1) throw new RuntimeException(new IllegalAccessException("waitTime should be >= 0"));
set(retrys, waitTime);
}

Expand Down
Expand Up @@ -99,7 +99,8 @@ else if (!dirFile.exists())

public static byte[] md5(byte[] buf)
{
try
if (buf==null) throw new IllegalArgumentException("buffer cannot be null!");
try
{
MessageDigest mdigest = MessageDigest.getInstance("MD5");
mdigest.update(buf, 0, buf.length);
Expand All @@ -116,6 +117,7 @@ public static byte[] md5(byte[] buf)
*/
public static String md5(File file)
{
if (file==null) throw new IllegalArgumentException("file cannot be null");
try
{
HashCode hc = Files.hash(file, Hashing.md5());
Expand All @@ -129,7 +131,8 @@ public static String md5(File file)

public static String toHex(byte[] digest)
{
StringBuffer sb = new StringBuffer(digest.length * 2);
if (digest==null) throw new IllegalArgumentException("digest cannot be null");
StringBuffer sb = new StringBuffer(digest.length * 2);
for (int i = 0; i < digest.length; i++)
{
String hex = Integer.toHexString(digest[i]);
Expand All @@ -148,6 +151,7 @@ else if (hex.length() == 8)

public static String toBase64(byte[] md5)
{
if (md5==null) throw new IllegalArgumentException("md5 cannot be null");
byte encoded[] = Base64.encodeBase64(md5, false);
return new String(encoded);
}
Expand Down

0 comments on commit 0fd0eb0

Please sign in to comment.