Merge pull request #11 from edwardcapriolo/logger-to-debug
Logger to debug
This commit is contained in:
8
pom.xml
8
pom.xml
@ -39,7 +39,13 @@
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.8.2</version>
|
||||
<version>4.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.teknek</groupId>
|
||||
<artifactId>tunit</artifactId>
|
||||
<version>0.0.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -30,7 +30,7 @@ public class GossipService {
|
||||
public GossipService(StartupSettings startupSettings) throws InterruptedException,
|
||||
UnknownHostException {
|
||||
this(InetAddress.getLocalHost().getHostAddress(), startupSettings.getPort(), "",
|
||||
startupSettings.getLogLevel(), startupSettings.getGossipMembers(), startupSettings
|
||||
startupSettings.getGossipMembers(), startupSettings
|
||||
.getGossipSettings(), null);
|
||||
}
|
||||
|
||||
@ -40,7 +40,7 @@ public class GossipService {
|
||||
* @throws InterruptedException
|
||||
* @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)
|
||||
throws InterruptedException, UnknownHostException {
|
||||
_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. */
|
||||
private int _port;
|
||||
|
||||
/** The logging level of the gossip service. */
|
||||
private int _logLevel;
|
||||
|
||||
/** The gossip settings used at startup. */
|
||||
private final GossipSettings _gossipSettings;
|
||||
|
||||
@ -38,7 +35,7 @@ public class StartupSettings {
|
||||
* The port to start the service on.
|
||||
*/
|
||||
public StartupSettings(int port, int logLevel) {
|
||||
this(port, logLevel, new GossipSettings());
|
||||
this(port, new GossipSettings());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -47,9 +44,8 @@ public class StartupSettings {
|
||||
* @param port
|
||||
* The port to start the service on.
|
||||
*/
|
||||
public StartupSettings(int port, int logLevel, GossipSettings gossipSettings) {
|
||||
public StartupSettings(int port, GossipSettings gossipSettings) {
|
||||
_port = port;
|
||||
_logLevel = logLevel;
|
||||
_gossipSettings = gossipSettings;
|
||||
_gossipMembers = new ArrayList<>();
|
||||
}
|
||||
@ -73,25 +69,6 @@ public class StartupSettings {
|
||||
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.
|
||||
*
|
||||
@ -149,20 +126,14 @@ public class StartupSettings {
|
||||
// Now get the port number.
|
||||
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.
|
||||
int gossipInterval = jsonObject.getInt("gossip_interval");
|
||||
|
||||
// Get the cleanup_interval from the config file.
|
||||
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.
|
||||
StartupSettings settings = new StartupSettings(port, logLevel, new GossipSettings(
|
||||
StartupSettings settings = new StartupSettings(port, new GossipSettings(
|
||||
gossipInterval, cleanupInterval));
|
||||
|
||||
// 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.GossipService;
|
||||
import com.google.code.gossip.GossipSettings;
|
||||
import com.google.code.gossip.LogLevel;
|
||||
import com.google.code.gossip.RemoteGossipMember;
|
||||
|
||||
/**
|
||||
@ -59,7 +58,7 @@ public class GossipExample extends Thread {
|
||||
// dead list handling.
|
||||
for (GossipMember member : startupMembers) {
|
||||
GossipService gossipService = new GossipService(myIpAddress, member.getPort(), "",
|
||||
LogLevel.DEBUG, startupMembers, settings, null);
|
||||
startupMembers, settings, null);
|
||||
clients.add(gossipService);
|
||||
gossipService.start();
|
||||
sleep(settings.getCleanupInterval() + 1000);
|
||||
|
@ -62,7 +62,7 @@ public abstract class GossipManager extends Thread implements NotificationListen
|
||||
this.listener = listener;
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
|
||||
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
|
||||
public void handleNotification(Notification notification, Object handback) {
|
||||
LocalGossipMember deadMember = (LocalGossipMember) notification.getUserData();
|
||||
GossipService.LOGGER.info("Dead member detected: " + deadMember);
|
||||
GossipService.LOGGER.debug("Dead member detected: " + deadMember);
|
||||
members.put(deadMember, GossipState.DOWN);
|
||||
if (listener != null) {
|
||||
listener.gossipEvent(deadMember, GossipState.DOWN);
|
||||
@ -138,13 +138,13 @@ public abstract class GossipManager extends Thread implements NotificationListen
|
||||
| InvocationTargetException | NoSuchMethodException | SecurityException e1) {
|
||||
throw new RuntimeException(e1);
|
||||
}
|
||||
GossipService.LOGGER.info("The GossipService is started.");
|
||||
GossipService.LOGGER.debug("The GossipService is started.");
|
||||
while (_gossipServiceRunning.get()) {
|
||||
try {
|
||||
// TODO
|
||||
TimeUnit.MILLISECONDS.sleep(1);
|
||||
} 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(),
|
||||
_gossipManager.getMyself().getPort());
|
||||
_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());
|
||||
GossipService.LOGGER.debug("I am " + _gossipManager.getMyself());
|
||||
} catch (SocketException ex) {
|
||||
GossipService.LOGGER.error(ex);
|
||||
GossipService.LOGGER.warn(ex);
|
||||
_server = null;
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ public class OnlyProcessReceivedPassiveGossipThread extends PassiveGossipThread
|
||||
// gossipManager.getMemberList().add(newLocalMember);
|
||||
gossipManager.createOrRevivieMember(newLocalMember);
|
||||
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.");
|
||||
}
|
||||
} else {
|
||||
@ -86,7 +86,7 @@ public class OnlyProcessReceivedPassiveGossipThread extends PassiveGossipThread
|
||||
gossipManager, gossipManager.getSettings().getCleanupInterval());
|
||||
gossipManager.createOrRevivieMember(newLocalMember);
|
||||
newLocalMember.startTimeoutTimer();
|
||||
GossipService.LOGGER.info("Added new remote member " + remoteMember.getAddress()
|
||||
GossipService.LOGGER.debug("Added new remote member " + remoteMember.getAddress()
|
||||
+ " to local member list.");
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +1,26 @@
|
||||
package io.teknek.gossip;
|
||||
|
||||
import io.teknek.tunit.TUnit;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
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 com.google.code.gossip.GossipMember;
|
||||
import com.google.code.gossip.GossipService;
|
||||
import com.google.code.gossip.GossipSettings;
|
||||
import com.google.code.gossip.LogLevel;
|
||||
import com.google.code.gossip.RemoteGossipMember;
|
||||
import com.google.code.gossip.event.GossipListener;
|
||||
import com.google.code.gossip.event.GossipState;
|
||||
|
||||
public class TenNodeThreeSeedTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void test() throws UnknownHostException, InterruptedException{
|
||||
abc();
|
||||
@ -36,10 +38,10 @@ public class TenNodeThreeSeedTest {
|
||||
for (int i = 1; i < seedNodes+1; ++i) {
|
||||
startupMembers.add(new RemoteGossipMember("127.0.0." + i, 2000, i + ""));
|
||||
}
|
||||
List<GossipService> clients = new ArrayList<>();
|
||||
int clusterMembers = 5;
|
||||
final List<GossipService> clients = new ArrayList<>();
|
||||
final int clusterMembers = 5;
|
||||
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,
|
||||
new GossipListener(){
|
||||
@Override
|
||||
@ -49,12 +51,16 @@ public class TenNodeThreeSeedTest {
|
||||
});
|
||||
clients.add(gossipService);
|
||||
gossipService.start();
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
Thread.sleep(10000);
|
||||
TUnit.assertThat(new Callable<Integer> (){
|
||||
public Integer call() throws Exception {
|
||||
int total = 0;
|
||||
for (int i = 0; i < clusterMembers; ++i) {
|
||||
Assert.assertEquals(4, clients.get(i).get_gossipManager().getMemberList().size());
|
||||
total += clients.get(i).get_gossipManager().getMemberList().size();
|
||||
}
|
||||
return total;
|
||||
}}).afterWaitingAtMost(10, TimeUnit.SECONDS).isEqualTo(20);
|
||||
|
||||
for (int i = 0; i < clusterMembers; ++i) {
|
||||
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