Merge pull request #11 from edwardcapriolo/logger-to-debug
Logger to debug
This commit is contained in:
8
pom.xml
8
pom.xml
@ -39,9 +39,15 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>4.8.2</version>
|
<version>4.11</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.teknek</groupId>
|
||||||
|
<artifactId>tunit</artifactId>
|
||||||
|
<version>0.0.0</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>log4j</groupId>
|
<groupId>log4j</groupId>
|
||||||
<artifactId>log4j</artifactId>
|
<artifactId>log4j</artifactId>
|
||||||
|
@ -30,7 +30,7 @@ public class GossipService {
|
|||||||
public GossipService(StartupSettings startupSettings) throws InterruptedException,
|
public GossipService(StartupSettings startupSettings) throws InterruptedException,
|
||||||
UnknownHostException {
|
UnknownHostException {
|
||||||
this(InetAddress.getLocalHost().getHostAddress(), startupSettings.getPort(), "",
|
this(InetAddress.getLocalHost().getHostAddress(), startupSettings.getPort(), "",
|
||||||
startupSettings.getLogLevel(), startupSettings.getGossipMembers(), startupSettings
|
startupSettings.getGossipMembers(), startupSettings
|
||||||
.getGossipSettings(), null);
|
.getGossipSettings(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ public class GossipService {
|
|||||||
* @throws InterruptedException
|
* @throws InterruptedException
|
||||||
* @throws UnknownHostException
|
* @throws UnknownHostException
|
||||||
*/
|
*/
|
||||||
public GossipService(String ipAddress, int port, String id, int logLevel,
|
public GossipService(String ipAddress, int port, String id,
|
||||||
List<GossipMember> gossipMembers, GossipSettings settings, GossipListener listener)
|
List<GossipMember> gossipMembers, GossipSettings settings, GossipListener listener)
|
||||||
throws InterruptedException, UnknownHostException {
|
throws InterruptedException, UnknownHostException {
|
||||||
_gossipManager = new RandomGossipManager(ipAddress, port, id, settings, gossipMembers, listener);
|
_gossipManager = new RandomGossipManager(ipAddress, port, id, settings, gossipMembers, listener);
|
||||||
|
@ -1,27 +0,0 @@
|
|||||||
package com.google.code.gossip;
|
|
||||||
|
|
||||||
public class LogLevel {
|
|
||||||
|
|
||||||
public static final String CONFIG_ERROR = "ERROR";
|
|
||||||
|
|
||||||
public static final String CONFIG_INFO = "INFO";
|
|
||||||
|
|
||||||
public static final String CONFIG_DEBUG = "DEBUG";
|
|
||||||
|
|
||||||
public static final int ERROR = 1;
|
|
||||||
|
|
||||||
public static final int INFO = 2;
|
|
||||||
|
|
||||||
public static final int DEBUG = 3;
|
|
||||||
|
|
||||||
public static int fromString(String logLevel) {
|
|
||||||
if (logLevel.equals(CONFIG_ERROR))
|
|
||||||
return ERROR;
|
|
||||||
else if (logLevel.equals(CONFIG_INFO))
|
|
||||||
return INFO;
|
|
||||||
else if (logLevel.equals(CONFIG_DEBUG))
|
|
||||||
return DEBUG;
|
|
||||||
else
|
|
||||||
return INFO;
|
|
||||||
}
|
|
||||||
}
|
|
@ -22,9 +22,6 @@ public class StartupSettings {
|
|||||||
/** The port to start the gossip service on. */
|
/** The port to start the gossip service on. */
|
||||||
private int _port;
|
private int _port;
|
||||||
|
|
||||||
/** The logging level of the gossip service. */
|
|
||||||
private int _logLevel;
|
|
||||||
|
|
||||||
/** The gossip settings used at startup. */
|
/** The gossip settings used at startup. */
|
||||||
private final GossipSettings _gossipSettings;
|
private final GossipSettings _gossipSettings;
|
||||||
|
|
||||||
@ -38,7 +35,7 @@ public class StartupSettings {
|
|||||||
* The port to start the service on.
|
* The port to start the service on.
|
||||||
*/
|
*/
|
||||||
public StartupSettings(int port, int logLevel) {
|
public StartupSettings(int port, int logLevel) {
|
||||||
this(port, logLevel, new GossipSettings());
|
this(port, new GossipSettings());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -47,9 +44,8 @@ public class StartupSettings {
|
|||||||
* @param port
|
* @param port
|
||||||
* The port to start the service on.
|
* The port to start the service on.
|
||||||
*/
|
*/
|
||||||
public StartupSettings(int port, int logLevel, GossipSettings gossipSettings) {
|
public StartupSettings(int port, GossipSettings gossipSettings) {
|
||||||
_port = port;
|
_port = port;
|
||||||
_logLevel = logLevel;
|
|
||||||
_gossipSettings = gossipSettings;
|
_gossipSettings = gossipSettings;
|
||||||
_gossipMembers = new ArrayList<>();
|
_gossipMembers = new ArrayList<>();
|
||||||
}
|
}
|
||||||
@ -73,25 +69,6 @@ public class StartupSettings {
|
|||||||
return _port;
|
return _port;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the log level of the gossip service.
|
|
||||||
*
|
|
||||||
* @param logLevel
|
|
||||||
* The log level({LogLevel}).
|
|
||||||
*/
|
|
||||||
public void setLogLevel(int logLevel) {
|
|
||||||
_logLevel = logLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the log level of the gossip service.
|
|
||||||
*
|
|
||||||
* @return The log level.
|
|
||||||
*/
|
|
||||||
public int getLogLevel() {
|
|
||||||
return _logLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the GossipSettings.
|
* Get the GossipSettings.
|
||||||
*
|
*
|
||||||
@ -149,20 +126,14 @@ public class StartupSettings {
|
|||||||
// Now get the port number.
|
// Now get the port number.
|
||||||
int port = jsonObject.getInt("port");
|
int port = jsonObject.getInt("port");
|
||||||
|
|
||||||
// Get the log level from the config file.
|
|
||||||
int logLevel = LogLevel.fromString(jsonObject.getString("log_level"));
|
|
||||||
|
|
||||||
// Get the gossip_interval from the config file.
|
// Get the gossip_interval from the config file.
|
||||||
int gossipInterval = jsonObject.getInt("gossip_interval");
|
int gossipInterval = jsonObject.getInt("gossip_interval");
|
||||||
|
|
||||||
// Get the cleanup_interval from the config file.
|
// Get the cleanup_interval from the config file.
|
||||||
int cleanupInterval = jsonObject.getInt("cleanup_interval");
|
int cleanupInterval = jsonObject.getInt("cleanup_interval");
|
||||||
|
|
||||||
System.out.println("Config [port: " + port + ", log_level: " + logLevel + ", gossip_interval: "
|
|
||||||
+ gossipInterval + ", cleanup_interval: " + cleanupInterval + "]");
|
|
||||||
|
|
||||||
// Initiate the settings with the port number.
|
// Initiate the settings with the port number.
|
||||||
StartupSettings settings = new StartupSettings(port, logLevel, new GossipSettings(
|
StartupSettings settings = new StartupSettings(port, new GossipSettings(
|
||||||
gossipInterval, cleanupInterval));
|
gossipInterval, cleanupInterval));
|
||||||
|
|
||||||
// Now iterate over the members from the config file and add them to the settings.
|
// Now iterate over the members from the config file and add them to the settings.
|
||||||
|
@ -8,7 +8,6 @@ import java.util.List;
|
|||||||
import com.google.code.gossip.GossipMember;
|
import com.google.code.gossip.GossipMember;
|
||||||
import com.google.code.gossip.GossipService;
|
import com.google.code.gossip.GossipService;
|
||||||
import com.google.code.gossip.GossipSettings;
|
import com.google.code.gossip.GossipSettings;
|
||||||
import com.google.code.gossip.LogLevel;
|
|
||||||
import com.google.code.gossip.RemoteGossipMember;
|
import com.google.code.gossip.RemoteGossipMember;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -59,7 +58,7 @@ public class GossipExample extends Thread {
|
|||||||
// dead list handling.
|
// dead list handling.
|
||||||
for (GossipMember member : startupMembers) {
|
for (GossipMember member : startupMembers) {
|
||||||
GossipService gossipService = new GossipService(myIpAddress, member.getPort(), "",
|
GossipService gossipService = new GossipService(myIpAddress, member.getPort(), "",
|
||||||
LogLevel.DEBUG, startupMembers, settings, null);
|
startupMembers, settings, null);
|
||||||
clients.add(gossipService);
|
clients.add(gossipService);
|
||||||
gossipService.start();
|
gossipService.start();
|
||||||
sleep(settings.getCleanupInterval() + 1000);
|
sleep(settings.getCleanupInterval() + 1000);
|
||||||
|
@ -62,7 +62,7 @@ public abstract class GossipManager extends Thread implements NotificationListen
|
|||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
|
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
GossipService.LOGGER.info("Service has been shutdown...");
|
GossipService.LOGGER.debug("Service has been shutdown...");
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@ -74,7 +74,7 @@ public abstract class GossipManager extends Thread implements NotificationListen
|
|||||||
@Override
|
@Override
|
||||||
public void handleNotification(Notification notification, Object handback) {
|
public void handleNotification(Notification notification, Object handback) {
|
||||||
LocalGossipMember deadMember = (LocalGossipMember) notification.getUserData();
|
LocalGossipMember deadMember = (LocalGossipMember) notification.getUserData();
|
||||||
GossipService.LOGGER.info("Dead member detected: " + deadMember);
|
GossipService.LOGGER.debug("Dead member detected: " + deadMember);
|
||||||
members.put(deadMember, GossipState.DOWN);
|
members.put(deadMember, GossipState.DOWN);
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
listener.gossipEvent(deadMember, GossipState.DOWN);
|
listener.gossipEvent(deadMember, GossipState.DOWN);
|
||||||
@ -138,13 +138,13 @@ public abstract class GossipManager extends Thread implements NotificationListen
|
|||||||
| InvocationTargetException | NoSuchMethodException | SecurityException e1) {
|
| InvocationTargetException | NoSuchMethodException | SecurityException e1) {
|
||||||
throw new RuntimeException(e1);
|
throw new RuntimeException(e1);
|
||||||
}
|
}
|
||||||
GossipService.LOGGER.info("The GossipService is started.");
|
GossipService.LOGGER.debug("The GossipService is started.");
|
||||||
while (_gossipServiceRunning.get()) {
|
while (_gossipServiceRunning.get()) {
|
||||||
try {
|
try {
|
||||||
// TODO
|
// TODO
|
||||||
TimeUnit.MILLISECONDS.sleep(1);
|
TimeUnit.MILLISECONDS.sleep(1);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
GossipService.LOGGER.info("The GossipClient was interrupted.");
|
GossipService.LOGGER.warn("The GossipClient was interrupted.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,11 +42,11 @@ abstract public class PassiveGossipThread implements Runnable {
|
|||||||
SocketAddress socketAddress = new InetSocketAddress(_gossipManager.getMyself().getHost(),
|
SocketAddress socketAddress = new InetSocketAddress(_gossipManager.getMyself().getHost(),
|
||||||
_gossipManager.getMyself().getPort());
|
_gossipManager.getMyself().getPort());
|
||||||
_server = new DatagramSocket(socketAddress);
|
_server = new DatagramSocket(socketAddress);
|
||||||
GossipService.LOGGER.info("Gossip service successfully initialized on port "
|
GossipService.LOGGER.debug("Gossip service successfully initialized on port "
|
||||||
+ _gossipManager.getMyself().getPort());
|
+ _gossipManager.getMyself().getPort());
|
||||||
GossipService.LOGGER.debug("I am " + _gossipManager.getMyself());
|
GossipService.LOGGER.debug("I am " + _gossipManager.getMyself());
|
||||||
} catch (SocketException ex) {
|
} catch (SocketException ex) {
|
||||||
GossipService.LOGGER.error(ex);
|
GossipService.LOGGER.warn(ex);
|
||||||
_server = null;
|
_server = null;
|
||||||
throw new RuntimeException(ex);
|
throw new RuntimeException(ex);
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ public class OnlyProcessReceivedPassiveGossipThread extends PassiveGossipThread
|
|||||||
// gossipManager.getMemberList().add(newLocalMember);
|
// gossipManager.getMemberList().add(newLocalMember);
|
||||||
gossipManager.createOrRevivieMember(newLocalMember);
|
gossipManager.createOrRevivieMember(newLocalMember);
|
||||||
newLocalMember.startTimeoutTimer();
|
newLocalMember.startTimeoutTimer();
|
||||||
GossipService.LOGGER.info("Removed remote member " + remoteMember.getAddress()
|
GossipService.LOGGER.debug("Removed remote member " + remoteMember.getAddress()
|
||||||
+ " from dead list and added to local member list.");
|
+ " from dead list and added to local member list.");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -86,7 +86,7 @@ public class OnlyProcessReceivedPassiveGossipThread extends PassiveGossipThread
|
|||||||
gossipManager, gossipManager.getSettings().getCleanupInterval());
|
gossipManager, gossipManager.getSettings().getCleanupInterval());
|
||||||
gossipManager.createOrRevivieMember(newLocalMember);
|
gossipManager.createOrRevivieMember(newLocalMember);
|
||||||
newLocalMember.startTimeoutTimer();
|
newLocalMember.startTimeoutTimer();
|
||||||
GossipService.LOGGER.info("Added new remote member " + remoteMember.getAddress()
|
GossipService.LOGGER.debug("Added new remote member " + remoteMember.getAddress()
|
||||||
+ " to local member list.");
|
+ " to local member list.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,26 @@
|
|||||||
package io.teknek.gossip;
|
package io.teknek.gossip;
|
||||||
|
|
||||||
|
import io.teknek.tunit.TUnit;
|
||||||
|
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import com.google.code.gossip.GossipMember;
|
import com.google.code.gossip.GossipMember;
|
||||||
import com.google.code.gossip.GossipService;
|
import com.google.code.gossip.GossipService;
|
||||||
import com.google.code.gossip.GossipSettings;
|
import com.google.code.gossip.GossipSettings;
|
||||||
import com.google.code.gossip.LogLevel;
|
|
||||||
import com.google.code.gossip.RemoteGossipMember;
|
import com.google.code.gossip.RemoteGossipMember;
|
||||||
import com.google.code.gossip.event.GossipListener;
|
import com.google.code.gossip.event.GossipListener;
|
||||||
import com.google.code.gossip.event.GossipState;
|
import com.google.code.gossip.event.GossipState;
|
||||||
|
|
||||||
public class TenNodeThreeSeedTest {
|
public class TenNodeThreeSeedTest {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() throws UnknownHostException, InterruptedException{
|
public void test() throws UnknownHostException, InterruptedException{
|
||||||
abc();
|
abc();
|
||||||
@ -36,10 +38,10 @@ public class TenNodeThreeSeedTest {
|
|||||||
for (int i = 1; i < seedNodes+1; ++i) {
|
for (int i = 1; i < seedNodes+1; ++i) {
|
||||||
startupMembers.add(new RemoteGossipMember("127.0.0." + i, 2000, i + ""));
|
startupMembers.add(new RemoteGossipMember("127.0.0." + i, 2000, i + ""));
|
||||||
}
|
}
|
||||||
List<GossipService> clients = new ArrayList<>();
|
final List<GossipService> clients = new ArrayList<>();
|
||||||
int clusterMembers = 5;
|
final int clusterMembers = 5;
|
||||||
for (int i = 1; i < clusterMembers+1; ++i) {
|
for (int i = 1; i < clusterMembers+1; ++i) {
|
||||||
GossipService gossipService = new GossipService("127.0.0." + i, 2000, i + "", LogLevel.DEBUG,
|
GossipService gossipService = new GossipService("127.0.0." + i, 2000, i + "",
|
||||||
startupMembers, settings,
|
startupMembers, settings,
|
||||||
new GossipListener(){
|
new GossipListener(){
|
||||||
@Override
|
@Override
|
||||||
@ -49,12 +51,16 @@ public class TenNodeThreeSeedTest {
|
|||||||
});
|
});
|
||||||
clients.add(gossipService);
|
clients.add(gossipService);
|
||||||
gossipService.start();
|
gossipService.start();
|
||||||
Thread.sleep(1000);
|
|
||||||
}
|
|
||||||
Thread.sleep(10000);
|
|
||||||
for (int i = 0; i < clusterMembers; ++i) {
|
|
||||||
Assert.assertEquals(4, clients.get(i).get_gossipManager().getMemberList().size());
|
|
||||||
}
|
}
|
||||||
|
TUnit.assertThat(new Callable<Integer> (){
|
||||||
|
public Integer call() throws Exception {
|
||||||
|
int total = 0;
|
||||||
|
for (int i = 0; i < clusterMembers; ++i) {
|
||||||
|
total += clients.get(i).get_gossipManager().getMemberList().size();
|
||||||
|
}
|
||||||
|
return total;
|
||||||
|
}}).afterWaitingAtMost(10, TimeUnit.SECONDS).isEqualTo(20);
|
||||||
|
|
||||||
for (int i = 0; i < clusterMembers; ++i) {
|
for (int i = 0; i < clusterMembers; ++i) {
|
||||||
clients.get(i).shutdown();
|
clients.get(i).shutdown();
|
||||||
}
|
}
|
||||||
|
8
src/test/resources/log4j.properties
Normal file
8
src/test/resources/log4j.properties
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
log4j.rootLogger=INFO,stdout
|
||||||
|
|
||||||
|
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||||
|
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||||
|
log4j.appender.stdout.layout.ConversionPattern=%5p %d{HH:mm:ss,SSS} %m%n
|
||||||
|
|
||||||
|
log4j.logger.io.teknek=DEBUG
|
||||||
|
log4j.logger.com.google.code.gossip=INFO
|
Reference in New Issue
Block a user