Skip to content

Commit

Permalink
Revert "updated tests to validate that context's executor is not shut…
Browse files Browse the repository at this point in the history
… down"

This reverts commit 9e06b6b.
  • Loading branch information
ceharris committed Apr 4, 2013
1 parent eb43def commit a35cb7a
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import java.net.InetAddress;
import java.net.ServerSocket;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import javax.net.ServerSocketFactory;

Expand All @@ -37,23 +35,19 @@ public class InstrumentedServerSocketAppenderBase
private final ServerSocket serverSocket;
private final ServerListener<RemoteLoggerClient> listener;
private final ServerRunner<RemoteLoggerClient> runner;
private final ExecutorService executor;

private ServerListener lastListener;

public InstrumentedServerSocketAppenderBase(ServerSocket serverSocket) {
this(serverSocket, new RemoteLoggerServerListener(serverSocket), null,
Executors.newCachedThreadPool());
this(serverSocket, new RemoteLoggerServerListener(serverSocket), null);
}

public InstrumentedServerSocketAppenderBase(ServerSocket serverSocket,
ServerListener<RemoteLoggerClient> listener,
ServerRunner<RemoteLoggerClient> runner,
ExecutorService executor) {
ServerRunner<RemoteLoggerClient> runner) {
this.serverSocket = serverSocket;
this.listener = listener;
this.runner = runner;
this.executor = executor;
}

@Override
Expand Down Expand Up @@ -92,6 +86,8 @@ public ServerSocket createServerSocket(int port, int backlog,
};
}



@Override
protected ServerRunner<RemoteLoggerClient> createServerRunner(
ServerListener<RemoteLoggerClient> listener, Executor executor) {
Expand All @@ -105,11 +101,6 @@ protected ServerListener<RemoteLoggerClient> createServerListener(
return listener;
}

@Override
protected ExecutorService createExecutor() {
return executor;
}

public ServerListener getLastListener() {
return lastListener;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* Logback: the reliable, generic, fast and flexible logging framework.
* Copyright (C) 1999-2011, QOS.ch. All rights reserved.
*
* This program and the accompanying materials are dual-licensed under
* either the terms of the Eclipse Public License v1.0 as published by
* the Eclipse Foundation
*
* or (per the licensee's choosing)
*
* under the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation.
*/
package ch.qos.logback.core.net.server;

import java.util.Collections;
import java.util.List;
import java.util.concurrent.AbstractExecutorService;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;

/**
* A mock {@link ThreadPoolFactoryBean} with instrumentation for unit testing.
*
* @author Carl Harris
*/
class MockThreadPoolFactoryBean extends ThreadPoolFactoryBean {

private final MockExecutorService executorService =
new MockExecutorService();

private Runnable lastCommand;

@Override
public ExecutorService createExecutor() {
return executorService;
}

public Runnable getLastCommand() {
return lastCommand;
}

private class MockExecutorService extends AbstractExecutorService {

public void shutdown() {
}

public List<Runnable> shutdownNow() {
return Collections.emptyList();
}

public boolean isShutdown() {
return true;
}

public boolean isTerminated() {
return true;
}

public boolean awaitTermination(long timeout, TimeUnit unit)
throws InterruptedException {
return true;
}

public void execute(Runnable command) {
lastCommand = command;
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
*/
public class ServerSocketAppenderBaseTest {

private MockExecutorService executorService = new MockExecutorService();


private MockContext context = new MockContext();

private MockServerRunner<RemoteLoggerClient> runner =
Expand All @@ -47,14 +46,17 @@ public class ServerSocketAppenderBaseTest {
private MockServerListener<RemoteLoggerClient> listener =
new MockServerListener<RemoteLoggerClient>();

private MockThreadPoolFactoryBean threadPool =
new MockThreadPoolFactoryBean();

private ServerSocket serverSocket;
private InstrumentedServerSocketAppenderBase appender;

@Before
public void setUp() throws Exception {
serverSocket = ServerSocketUtil.createServerSocket();
appender = new InstrumentedServerSocketAppenderBase(
serverSocket, listener, runner, executorService);
appender = new InstrumentedServerSocketAppenderBase(serverSocket, listener, runner);
appender.setThreadPool(threadPool);
appender.setContext(context);
}

Expand All @@ -72,23 +74,6 @@ public void testStartStop() throws Exception {

appender.stop();
assertFalse(runner.isStarted());
assertTrue(executorService.isShutdown());
}

@Test
public void testStartStopWithContextExecutorService() throws Exception {
appender = new InstrumentedServerSocketAppenderBase(serverSocket, listener, runner,
context.getExecutorService());
appender.setContext(context);
appender.start();
assertTrue(runner.isContextInjected());
assertTrue(runner.isStarted());
assertSame(listener, appender.getLastListener());

appender.stop();
assertFalse(runner.isStarted());
// we should not shut down the context's executor service
assertFalse(executorService.isShutdown());
}

@Test
Expand Down

0 comments on commit a35cb7a

Please sign in to comment.