Skip to content

Commit

Permalink
bump version number
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmcclean committed Apr 21, 2015
2 parents 0273276 + 3521be6 commit 3127bed
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 8 deletions.
4 changes: 4 additions & 0 deletions micro-boot/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ dependencies {
compile 'org.springframework.boot:spring-boot:1.2.1.RELEASE'
compile 'org.springframework.boot:spring-boot-autoconfigure:1.2.1.RELEASE'
//compile project(':micro-core')
<<<<<<< HEAD
compile group: 'com.aol.microservices', name:'microserver-core', version:'0.55'
=======
compile group: 'com.aol.microservices', name:'microserver-core', version:'0.54'
>>>>>>> 3521be673c00ffe96533acc6ff62127cc80bc0a7

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Supplier;

import javax.servlet.Filter;
import javax.servlet.Servlet;
import javax.servlet.ServletContextListener;

import org.glassfish.grizzly.http.server.HttpServer;

import lombok.AllArgsConstructor;
import lombok.experimental.Builder;
import lombok.experimental.Wither;
Expand Down Expand Up @@ -38,8 +41,17 @@ public class ConfigurableModule implements Module{
private final Set<Class> springConfigurationClasses;
private final Map<String,String> propertyOverrides;
private final List<String> defaultJaxRsPackages;
private final Consumer<HttpServer> serverConfigManager;
private final boolean resetAll;

@Override
public Consumer<HttpServer> getServerConfigManager(){
if(serverConfigManager!=null)
return serverConfigManager;

return Module.super.getServerConfigManager();
}

@Override
public List<String> getDefaultJaxRsPackages() {
if(defaultJaxRsPackages!=null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.aol.micro.server.module;

import java.net.InetAddress;
import java.util.Collection;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import java.util.stream.Collectors;

import org.jooq.lambda.fi.util.function.CheckedSupplier;

import com.aol.simple.react.exceptions.ExceptionSoftener;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;

Expand Down Expand Up @@ -34,12 +38,21 @@ public void assureModule(Module module) {
if (!modulePort.containsKey(module.getContext())) {
Map<String, ModuleBean> builder = Maps.newHashMap();
builder.putAll(modulePort);
builder.put(module.getContext(), ModuleBean.builder().port(getPort(module)).build());
builder.put(module.getContext(), ModuleBean.builder().host(getHost(module)).port(getPort(module)).build());
modulePort = ImmutableMap.copyOf(builder);
}

}

private String getHost(Module module) {
CheckedSupplier<String> s = ()->InetAddress.getLocalHost().getHostName();
try{
return Optional.ofNullable(properties.get(module.getContext() + ".host")).orElse(s.get()).toString();
}catch(Throwable e){
throw new RuntimeException(e);
}
}

private int getPort(Module module) {

return Integer.valueOf(Optional.ofNullable(properties.get(module.getContext() + ".port")).orElse(nextPort++).toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;

import javax.servlet.Filter;
import javax.servlet.Servlet;
import javax.servlet.ServletContextListener;

import org.glassfish.grizzly.http.server.HttpServer;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.WebApplicationContext;

Expand All @@ -32,6 +34,9 @@

public interface Module {

default Consumer<HttpServer> getServerConfigManager(){
return server->{};
}
default List<String> getPackages(){
return ImmutableList.of();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void run(CompletableFuture start, CompletableFuture end) {
addListeners(webappContext);

HttpServer httpServer = HttpServer.createSimpleServer(null, "0.0.0.0", serverData.getPort());

serverData.getModule().getServerConfigManager().accept(httpServer);
addAccessLog(httpServer);
if (SSLProperties != null)
this.createSSLListener(serverData.getPort());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package app.single.serverconfig.com.aol.micro.server;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*;

import java.util.concurrent.ExecutionException;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.aol.micro.server.MicroserverApp;
import com.aol.micro.server.auto.discovery.RestResource;
import com.aol.micro.server.config.Microserver;
import com.aol.micro.server.module.ConfigurableModule;
import com.aol.micro.server.testing.RestAgent;


@Path("/single")
public class SingleClassTest implements RestResource{

RestAgent rest = new RestAgent();

boolean called;
MicroserverApp server;
@Before
public void startServer(){
called = false;
server = new MicroserverApp( ConfigurableModule.builder()
.context("hello")
.serverConfigManager(server->called=true)
.build());
server.start();

}

@After
public void stopServer(){
server.stop();
}

@Test
public void runAppAndBasicTest() throws InterruptedException, ExecutionException{



assertThat(rest.get("http://localhost:8080/hello/single/ping"),is("ok"));
assertTrue(called);

}

@GET
@Produces("text/plain")
@Path("/ping")
public String ping() {
return "ok";
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@

import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;

import javax.servlet.Filter;
import javax.servlet.Servlet;
import javax.servlet.ServletContextListener;

import org.glassfish.grizzly.http.server.HttpServer;
import org.junit.Before;
import org.junit.Test;

Expand All @@ -40,6 +42,7 @@ public class ConfigurableModuleTest {
private List<String> defaultJaxRsPackages;

private Module m = () -> "module";
Consumer<HttpServer> serverConfigManager = server-> {};
@Before
public void setup(){

Expand All @@ -55,7 +58,9 @@ public void setup(){
servlets = new HashMap<>();
springConfigurationClasses = ImmutableSet.of(this.getClass());


module = ConfigurableModule.builder()
.serverConfigManager(serverConfigManager )
.defaultJaxRsPackages(defaultJaxRsPackages)
.context(context)
.defaultResources(defaultResources)
Expand All @@ -73,6 +78,19 @@ public void setup(){
.build();
}
@Test
public void testGetServerConfigManager() {
assertThat(module.withResetAll(true).getServerConfigManager(),is(serverConfigManager));
}
@Test
public void testGetServerConfigManagerNull() {
try {
module.withServerConfigManager(null)
.getServerConfigManager().accept(null);
}catch(Exception e){
fail(e.getMessage());
}
}
@Test
public void testGetRestResourceClassesResetAll() {
assertThat(module.withResetAll(true).getRestResourceClasses(),is(resourceClasses));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.aol.micro.server.module;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Properties;

import org.junit.Test;
Expand Down Expand Up @@ -37,4 +39,28 @@ public void testGetModuleBeanOverridePort() {
environment.assureModule(() ->"context");
assertThat(environment.getModuleBean(()-> "context").getPort(), is(8081));
}

@Test
public void testDefaultHost() throws UnknownHostException {
String host =InetAddress.getLocalHost().getHostName();
Environment environment = new Environment(new Properties());
environment.assureModule(() ->"context");
assertThat(environment.getModuleBean(()-> "context").getHost(), is(host));
}
@Test
public void testDefaultHostNotNull() throws UnknownHostException {

Environment environment = new Environment(new Properties());
environment.assureModule(() ->"context");
assertThat(environment.getModuleBean(()-> "context").getHost(), is(not(nullValue())));
}
@Test
public void testHostOverride() throws UnknownHostException {

Properties props = new Properties();
props.put("context.host", "overriden-host");
Environment environment = new Environment(props);
environment.assureModule(() ->"context");
assertThat(environment.getModuleBean(()-> "context").getHost(), is("overriden-host"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class ServerRunnerTest {
private GrizzlyApplication serverApplication1;
private GrizzlyApplication serverApplication2;
private ServerData[] registered;
int server1Count =0;
int server2Count =0;
volatile int server1Count =0;
volatile int server2Count =0;
@Before
public void setUp() {

Expand All @@ -35,14 +35,16 @@ public void setUp() {

serverApplication1 = new GrizzlyApplication(AllData.builder().serverData(data1).build()){
public void run(CompletableFuture start,CompletableFuture end) {
start.complete(true);
server1Count++;
start.complete(true);

}
};
serverApplication2 = new GrizzlyApplication(AllData.builder().serverData(data2).build()){
public void run(CompletableFuture start,CompletableFuture end) {
start.complete(true);
server2Count++;
start.complete(true);

}
};

Expand Down

0 comments on commit 3127bed

Please sign in to comment.