Fix some typos
Change-Id: Ia877cc10f76e27c1d12ffdbbff399dd89e25f319
This commit is contained in:
parent
f8e0cc44f9
commit
96a294828b
3 changed files with 16 additions and 16 deletions
|
@ -10,15 +10,15 @@ import java.util.concurrent.CopyOnWriteArrayList
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@PackageScope
|
@PackageScope
|
||||||
class ContextExecutor {
|
class ContextExecutor {
|
||||||
private final HttpServerWraper httpServerWraper
|
private final HttpServerWrapper httpServerWrapper
|
||||||
final String path
|
final String path
|
||||||
private final List<Mock> mocks
|
private final List<Mock> mocks
|
||||||
|
|
||||||
ContextExecutor(HttpServerWraper httpServerWraper, Mock initialMock) {
|
ContextExecutor(HttpServerWrapper httpServerWrapper, Mock initialMock) {
|
||||||
this.httpServerWraper = httpServerWraper
|
this.httpServerWrapper = httpServerWrapper
|
||||||
this.path = "/${initialMock.path}"
|
this.path = "/${initialMock.path}"
|
||||||
this.mocks = new CopyOnWriteArrayList<>([initialMock])
|
this.mocks = new CopyOnWriteArrayList<>([initialMock])
|
||||||
httpServerWraper.createContext(path) {
|
httpServerWrapper.createContext(path) {
|
||||||
HttpExchange ex ->
|
HttpExchange ex ->
|
||||||
try {
|
try {
|
||||||
applyMocks(ex)
|
applyMocks(ex)
|
||||||
|
|
|
@ -30,8 +30,8 @@ import static pl.touk.mockserver.server.Util.createResponse
|
||||||
@Slf4j
|
@Slf4j
|
||||||
class HttpMockServer {
|
class HttpMockServer {
|
||||||
|
|
||||||
private final HttpServerWraper httpServerWraper
|
private final HttpServerWrapper httpServerWrapper
|
||||||
private final Map<Integer, HttpServerWraper> childServers = new ConcurrentHashMap<>()
|
private final Map<Integer, HttpServerWrapper> childServers = new ConcurrentHashMap<>()
|
||||||
private final Set<String> mockNames = new CopyOnWriteArraySet<>()
|
private final Set<String> mockNames = new CopyOnWriteArraySet<>()
|
||||||
private final ConfigObject configuration = new ConfigObject()
|
private final ConfigObject configuration = new ConfigObject()
|
||||||
private final Executor executor
|
private final Executor executor
|
||||||
|
@ -41,13 +41,13 @@ class HttpMockServer {
|
||||||
|
|
||||||
HttpMockServer(int port = 9999, ConfigObject initialConfiguration = new ConfigObject(), int threads = 10) {
|
HttpMockServer(int port = 9999, ConfigObject initialConfiguration = new ConfigObject(), int threads = 10) {
|
||||||
executor = Executors.newFixedThreadPool(threads)
|
executor = Executors.newFixedThreadPool(threads)
|
||||||
httpServerWraper = new HttpServerWraper(port, executor)
|
httpServerWrapper = new HttpServerWrapper(port, executor)
|
||||||
|
|
||||||
initialConfiguration.values()?.each { ConfigObject co ->
|
initialConfiguration.values()?.each { ConfigObject co ->
|
||||||
addMock(co)
|
addMock(co)
|
||||||
}
|
}
|
||||||
|
|
||||||
httpServerWraper.createContext('/serverControl', {
|
httpServerWrapper.createContext('/serverControl', {
|
||||||
HttpExchange ex ->
|
HttpExchange ex ->
|
||||||
try {
|
try {
|
||||||
if (ex.requestMethod == 'GET') {
|
if (ex.requestMethod == 'GET') {
|
||||||
|
@ -108,7 +108,7 @@ class HttpMockServer {
|
||||||
throw new RuntimeException('mock already registered')
|
throw new RuntimeException('mock already registered')
|
||||||
}
|
}
|
||||||
Mock mock = mockFromRequest(request)
|
Mock mock = mockFromRequest(request)
|
||||||
HttpServerWraper child = getOrCreateChildServer(mock.port)
|
HttpServerWrapper child = getOrCreateChildServer(mock.port)
|
||||||
child.addMock(mock)
|
child.addMock(mock)
|
||||||
saveConfiguration(request)
|
saveConfiguration(request)
|
||||||
mockNames << name
|
mockNames << name
|
||||||
|
@ -121,7 +121,7 @@ class HttpMockServer {
|
||||||
throw new RuntimeException('mock already registered')
|
throw new RuntimeException('mock already registered')
|
||||||
}
|
}
|
||||||
Mock mock = mockFromConfig(co)
|
Mock mock = mockFromConfig(co)
|
||||||
HttpServerWraper child = getOrCreateChildServer(mock.port)
|
HttpServerWrapper child = getOrCreateChildServer(mock.port)
|
||||||
child.addMock(mock)
|
child.addMock(mock)
|
||||||
configuration.put(name, co)
|
configuration.put(name, co)
|
||||||
mockNames << name
|
mockNames << name
|
||||||
|
@ -173,10 +173,10 @@ class HttpMockServer {
|
||||||
return mock
|
return mock
|
||||||
}
|
}
|
||||||
|
|
||||||
private HttpServerWraper getOrCreateChildServer(int mockPort) {
|
private HttpServerWrapper getOrCreateChildServer(int mockPort) {
|
||||||
HttpServerWraper child = childServers[mockPort]
|
HttpServerWrapper child = childServers[mockPort]
|
||||||
if (!child) {
|
if (!child) {
|
||||||
child = new HttpServerWraper(mockPort, executor)
|
child = new HttpServerWrapper(mockPort, executor)
|
||||||
childServers.put(mockPort, child)
|
childServers.put(mockPort, child)
|
||||||
}
|
}
|
||||||
return child
|
return child
|
||||||
|
@ -244,6 +244,6 @@ class HttpMockServer {
|
||||||
|
|
||||||
void stop() {
|
void stop() {
|
||||||
childServers.values().each { it.stop() }
|
childServers.values().each { it.stop() }
|
||||||
httpServerWraper.stop()
|
httpServerWrapper.stop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,13 +9,13 @@ import java.util.concurrent.Executor
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@PackageScope
|
@PackageScope
|
||||||
class HttpServerWraper {
|
class HttpServerWrapper {
|
||||||
private final HttpServer httpServer
|
private final HttpServer httpServer
|
||||||
final int port
|
final int port
|
||||||
|
|
||||||
private List<ContextExecutor> executors = []
|
private List<ContextExecutor> executors = []
|
||||||
|
|
||||||
HttpServerWraper(int port, Executor executor) {
|
HttpServerWrapper(int port, Executor executor) {
|
||||||
this.port = port
|
this.port = port
|
||||||
InetSocketAddress addr = new InetSocketAddress(Inet4Address.getByName("0.0.0.0"), port)
|
InetSocketAddress addr = new InetSocketAddress(Inet4Address.getByName("0.0.0.0"), port)
|
||||||
httpServer = HttpServer.create(addr, 0)
|
httpServer = HttpServer.create(addr, 0)
|
Loading…
Add table
Add a link
Reference in a new issue