Skip to content

Commit

Permalink
Merge pull request #64 from NiteshKant/master
Browse files Browse the repository at this point in the history
Fix for issue #62
  • Loading branch information
NiteshKant committed May 8, 2014
2 parents 7356931 + 1a3aef2 commit 861ab6c
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 29 deletions.
17 changes: 12 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
// Establish version and status
ext.githubProjectName = rootProject.name // Change if github project name is not the same as the root project's name

ext {
governatorVersion="[1.2.7,2.0)"
archaiusVersion="[0.5.4,1.0)"
pytheasVersion="1.11"
eurekaVersion="[1.1.73,2.0)"
}

buildscript {
repositories {
mavenLocal()
Expand Down Expand Up @@ -56,7 +63,7 @@ subprojects {

project(':karyon-spi') {
dependencies {
compile('com.netflix.governator:governator:1.1.1') {
compile("com.netflix.governator:governator:$governatorVersion") {
exclude module: 'archaius-core'
}
}
Expand All @@ -65,10 +72,10 @@ project(':karyon-spi') {
project(':karyon-eureka') {
dependencies {
compile project(':karyon-spi')
compile('com.netflix.archaius:archaius-core:0.5.4') {
compile("com.netflix.archaius:archaius-core:$archaiusVersion") {
force = true
}
compile 'com.netflix.eureka:eureka-client:1.1.73'
compile "com.netflix.eureka:eureka-client:$eurekaVersion"
}
}

Expand Down Expand Up @@ -113,9 +120,10 @@ project(':karyon-admin') {
compile 'javax.servlet:servlet-api:2.5'
compile 'org.eclipse.jetty:jetty-server:7.6.7.v20120910'
compile 'org.eclipse.jetty:jetty-servlet:7.6.7.v20120910'
compile 'com.sun.jersey:jersey-servlet:1.11'
compile 'com.sun.jersey.contribs:jersey-guice:1.8'
compile 'com.google.inject.extensions:guice-servlet:3.0'
compile 'com.netflix.pytheas:pytheas-core:1.11'
compile "com.netflix.pytheas:pytheas-core:$pytheasVersion"
runtime 'org.codehaus.jackson:jackson-mapper-asl:1.9.11'
}
}
Expand All @@ -124,7 +132,6 @@ project(':karyon-admin-web') {
dependencies {
compile project(':karyon-admin')
compile 'com.google.code.gson:gson:2.1'
compile 'com.netflix.pytheas:pytheas-core:1.11'
runtime 'org.freemarker:freemarker:2.3.15'
runtime 'org.codehaus.jackson:jackson-mapper-asl:1.9.11'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@
package com.netflix.adminresources;

import com.google.inject.Injector;
import com.netflix.config.ConcurrentCompositeConfiguration;
import com.netflix.config.ConfigurationManager;
import com.netflix.karyon.server.KaryonServer;
import com.netflix.karyon.server.eureka.SyncHealthCheckInvocationStrategy;
import com.netflix.karyon.spi.PropertyNames;
import junit.framework.Assert;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.HttpHostConnectException;
import org.apache.http.impl.client.DefaultHttpClient;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

Expand All @@ -51,6 +52,8 @@ public void setUp() throws Exception {
public void tearDown() throws Exception {
ConfigurationManager.getConfigInstance().clearProperty(PropertyNames.DISABLE_APPLICATION_DISCOVERY_PROP_NAME);
ConfigurationManager.getConfigInstance().clearProperty(PropertyNames.EXPLICIT_APPLICATION_CLASS_PROP_NAME);
((ConcurrentCompositeConfiguration) ConfigurationManager.getConfigInstance())
.clearOverrideProperty(AdminResourcesContainer.CONTAINER_LISTEN_PORT);
server.close();
}

Expand All @@ -66,7 +69,8 @@ public void testBasic() throws Exception {

@Test (expected = HttpHostConnectException.class)
public void testCustomPort() throws Exception {
ConfigurationManager.getConfigInstance().setProperty(AdminResourcesContainer.CONTAINER_LISTEN_PORT, CUSTOM_LISTEN_PORT);
((ConcurrentCompositeConfiguration) ConfigurationManager.getConfigInstance())
.setOverrideProperty(AdminResourcesContainer.CONTAINER_LISTEN_PORT, CUSTOM_LISTEN_PORT);
startServer();
HttpClient client = new DefaultHttpClient();
HttpGet healthGet = new HttpGet("http://localhost:"+ AdminResourcesContainer.LISTEN_PORT_DEFAULT + "/healthcheck");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
package com.netflix.karyon.server;

import com.netflix.appinfo.InstanceInfo;
import com.netflix.config.ConfigurationManager;
import com.netflix.discovery.DiscoveryManager;
import com.netflix.karyon.spi.PropertyNames;
import com.netflix.karyon.util.EurekaResourceMock;
import junit.framework.Assert;
import com.netflix.karyon.util.KaryonTestSetupUtil;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

Expand Down Expand Up @@ -54,7 +54,7 @@ public void setUp() throws Exception {
@After
public void tearDown() throws Exception {
eurekaResourceMock.stop();
ConfigurationManager.getConfigInstance().setProperty(PropertyNames.DISABLE_EUREKA_INTEGRATION, "true");
KaryonTestSetupUtil.setOverrideProperty(PropertyNames.DISABLE_EUREKA_INTEGRATION, "true");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.netflix.karyon.server;

import com.google.inject.Injector;
import com.netflix.config.ConfigurationManager;
import com.netflix.karyon.server.eureka.AsyncHealthCheckInvocationStrategy;
import com.netflix.karyon.server.eureka.EurekaHealthCheckCallback;
import com.netflix.karyon.server.eureka.SyncHealthCheckInvocationStrategy;
Expand All @@ -31,8 +30,8 @@
import com.test.TestComponent;
import com.testmulti.TestApplication2;
import com.testmulti.TestApplication3;
import junit.framework.Assert;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
Expand All @@ -54,6 +53,10 @@ public void setUp() throws Exception {
@After
public void tearDown() throws Exception {
KaryonTestSetupUtil.tearDown(server);
KaryonTestSetupUtil.clearOverrideProperties(PropertyNames.DISABLE_APPLICATION_DISCOVERY_PROP_NAME);
KaryonTestSetupUtil.clearOverrideProperties(PropertyNames.HEALTH_CHECK_HANDLER_CLASS_PROP_NAME);
KaryonTestSetupUtil.clearOverrideProperties(PropertyNames.SERVER_BOOTSTRAP_BASE_PACKAGES_OVERRIDE);
KaryonTestSetupUtil.clearOverrideProperties(PropertyNames.EXPLICIT_APPLICATION_CLASS_PROP_NAME);
}

@Test
Expand All @@ -75,8 +78,8 @@ public void testAnnotatedClasses() throws Exception {

@Test
public void testOnlyAnnotatedComponent() throws Exception {
ConfigurationManager.getConfigInstance().setProperty(PropertyNames.DISABLE_APPLICATION_DISCOVERY_PROP_NAME,
true);
KaryonTestSetupUtil.setOverrideProperty(PropertyNames.DISABLE_APPLICATION_DISCOVERY_PROP_NAME,
true);

startServer();
Assert.assertTrue("Component not initialized.", RegistrationSequence.contains(TestComponent.class));
Expand All @@ -85,8 +88,8 @@ public void testOnlyAnnotatedComponent() throws Exception {

@Test
public void testHealthCheck() throws Exception {
ConfigurationManager.getConfigInstance().setProperty(PropertyNames.HEALTH_CHECK_HANDLER_CLASS_PROP_NAME,
HealthCheckGuy.class.getName());
KaryonTestSetupUtil.setOverrideProperty(PropertyNames.HEALTH_CHECK_HANDLER_CLASS_PROP_NAME,
HealthCheckGuy.class.getName());

Injector injector = startServer();
injector.getInstance(EurekaHealthCheckCallback.class);
Expand All @@ -95,11 +98,11 @@ public void testHealthCheck() throws Exception {

@Test
public void testHealthCheckTimeout() throws Exception {
ConfigurationManager.getConfigInstance().setProperty(PropertyNames.HEALTH_CHECK_STRATEGY,
AsyncHealthCheckInvocationStrategy.class.getName());
KaryonTestSetupUtil.setOverrideProperty(PropertyNames.HEALTH_CHECK_STRATEGY,
AsyncHealthCheckInvocationStrategy.class.getName());

ConfigurationManager.getConfigInstance().setProperty(PropertyNames.HEALTH_CHECK_HANDLER_CLASS_PROP_NAME,
RogueHealthCheck.class.getName());
KaryonTestSetupUtil.setOverrideProperty(PropertyNames.HEALTH_CHECK_HANDLER_CLASS_PROP_NAME,
RogueHealthCheck.class.getName());

Injector injector = startServer();
EurekaHealthCheckCallback eurekaHealthCheckCallback = injector.getInstance(EurekaHealthCheckCallback.class);
Expand All @@ -108,11 +111,11 @@ public void testHealthCheckTimeout() throws Exception {

@Test
public void testFlappingHealthCheck() throws Exception {
ConfigurationManager.getConfigInstance().setProperty(PropertyNames.HEALTH_CHECK_STRATEGY,
SyncHealthCheckInvocationStrategy.class.getName());
KaryonTestSetupUtil.setOverrideProperty(PropertyNames.HEALTH_CHECK_STRATEGY,
SyncHealthCheckInvocationStrategy.class.getName());

ConfigurationManager.getConfigInstance().setProperty(PropertyNames.HEALTH_CHECK_HANDLER_CLASS_PROP_NAME,
FlappingHealthCheck.class.getName());
KaryonTestSetupUtil.setOverrideProperty(PropertyNames.HEALTH_CHECK_HANDLER_CLASS_PROP_NAME,
FlappingHealthCheck.class.getName());

Injector injector = startServer();
EurekaHealthCheckCallback eurekaHealthCheckCallback = injector.getInstance(EurekaHealthCheckCallback.class);
Expand All @@ -122,8 +125,8 @@ public void testFlappingHealthCheck() throws Exception {

@Test
public void testHealthCheckSuccess() throws Exception {
ConfigurationManager.getConfigInstance().setProperty(PropertyNames.HEALTH_CHECK_HANDLER_CLASS_PROP_NAME,
HealthCheckGuy.class.getName());
KaryonTestSetupUtil.setOverrideProperty(PropertyNames.HEALTH_CHECK_HANDLER_CLASS_PROP_NAME,
HealthCheckGuy.class.getName());

Injector injector = startServer();
EurekaHealthCheckCallback eurekaHealthCheckCallback = injector.getInstance(EurekaHealthCheckCallback.class);
Expand All @@ -132,9 +135,10 @@ public void testHealthCheckSuccess() throws Exception {

@Test
public void testMultipleApps() throws Exception {
ConfigurationManager.getConfigInstance().setProperty(PropertyNames.SERVER_BOOTSTRAP_BASE_PACKAGES_OVERRIDE, "com.test,com.testmulti");
ConfigurationManager.getConfigInstance().setProperty(PropertyNames.EXPLICIT_APPLICATION_CLASS_PROP_NAME,
TestApplication3.class.getName());
KaryonTestSetupUtil.setOverrideProperty(PropertyNames.SERVER_BOOTSTRAP_BASE_PACKAGES_OVERRIDE,
"com.test,com.testmulti");
KaryonTestSetupUtil.setOverrideProperty(PropertyNames.EXPLICIT_APPLICATION_CLASS_PROP_NAME,
TestApplication3.class.getName());
startServer();

Assert.assertTrue("Component not initialized.", RegistrationSequence.contains(TestComponent.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.netflix.karyon.util;

import com.google.inject.Injector;
import com.netflix.config.ConcurrentCompositeConfiguration;
import com.netflix.config.ConfigurationManager;
import com.netflix.karyon.server.KaryonServer;
import com.netflix.karyon.spi.PropertyNames;
Expand Down Expand Up @@ -45,4 +46,13 @@ public static Injector startServer(KaryonServer server) throws Exception {
server.start();
return injector;
}

public static void clearOverrideProperties(String name) {
((ConcurrentCompositeConfiguration) ConfigurationManager.getConfigInstance()).clearOverrideProperty(name);
}

public static <T> void setOverrideProperty(String name, T value) {
((ConcurrentCompositeConfiguration) ConfigurationManager.getConfigInstance())
.setOverrideProperty(name, value);
}
}

0 comments on commit 861ab6c

Please sign in to comment.