use of org.apache.geode.distributed.internal.DistributionConfig in project geode by apache.
the class LogWriterUtils method createLogWriter.
/**
* Creates a new LogWriter and adds it to the config properties. The config can then be used to
* connect to DistributedSystem, thus providing early access to the LogWriter before connecting.
* This call does not connect to the DistributedSystem. It simply creates and returns the
* LogWriter that will eventually be used by the DistributedSystem that connects using config.
*
* @param properties the DistributedSystem config properties to add LogWriter to
* @return early access to the DistributedSystem LogWriter
* @deprecated Please use a <code>Logger</code> from {@link LogService#getLogger()} instead.
*/
public static LogWriter createLogWriter(final Properties properties) {
Properties nonDefault = properties;
if (nonDefault == null) {
nonDefault = new Properties();
}
DistributedTestUtils.addHydraProperties(nonDefault);
DistributionConfig dc = new DistributionConfigImpl(nonDefault);
LogWriter logger = LogWriterFactory.createLogWriterLogger(false, /* isLoner */
false, /* isSecurityLog */
dc, false);
// if config was non-null, then these will be added to it...
nonDefault.put(DistributionConfig.LOG_WRITER_NAME, logger);
return logger;
}
use of org.apache.geode.distributed.internal.DistributionConfig in project geode by apache.
the class ServerStarterRule method startServer.
public void startServer() {
CacheFactory cf = new CacheFactory(this.properties);
cf.setPdxReadSerialized(pdxPersistent);
cf.setPdxPersistent(pdxPersistent);
cache = cf.create();
DistributionConfig config = ((InternalDistributedSystem) cache.getDistributedSystem()).getConfig();
server = cache.addCacheServer();
server.setPort(0);
try {
server.start();
} catch (IOException e) {
throw new RuntimeException("unable to start server", e);
}
memberPort = server.getPort();
jmxPort = config.getJmxManagerPort();
httpPort = config.getHttpServicePort();
}
use of org.apache.geode.distributed.internal.DistributionConfig in project geode by apache.
the class AcceptorImplJUnitTest method testConstructor.
/*
* Test method for 'org.apache.geode.internal.cache.tier.sockets.AcceptorImpl(int, int, boolean,
* int, Cache)'
*/
@Ignore
@Test
public void testConstructor() throws CacheException, IOException {
AcceptorImpl a1 = null, a2 = null, a3 = null;
try {
final int[] freeTCPPorts = AvailablePortHelper.getRandomAvailableTCPPorts(2);
int port1 = freeTCPPorts[0];
int port2 = freeTCPPorts[1];
try {
new AcceptorImpl(port1, null, false, CacheServer.DEFAULT_SOCKET_BUFFER_SIZE, CacheServer.DEFAULT_MAXIMUM_TIME_BETWEEN_PINGS, this.cache, AcceptorImpl.MINIMUM_MAX_CONNECTIONS - 1, CacheServer.DEFAULT_MAX_THREADS, CacheServer.DEFAULT_MAXIMUM_MESSAGE_COUNT, CacheServer.DEFAULT_MESSAGE_TIME_TO_LIVE, null, null, false, Collections.EMPTY_LIST, CacheServer.DEFAULT_TCP_NO_DELAY);
fail("Expected an IllegalArgumentExcption due to max conns < min pool size");
} catch (IllegalArgumentException expected) {
}
try {
new AcceptorImpl(port2, null, false, CacheServer.DEFAULT_SOCKET_BUFFER_SIZE, CacheServer.DEFAULT_MAXIMUM_TIME_BETWEEN_PINGS, this.cache, 0, CacheServer.DEFAULT_MAX_THREADS, CacheServer.DEFAULT_MAXIMUM_MESSAGE_COUNT, CacheServer.DEFAULT_MESSAGE_TIME_TO_LIVE, null, null, false, Collections.EMPTY_LIST, CacheServer.DEFAULT_TCP_NO_DELAY);
fail("Expected an IllegalArgumentExcption due to max conns of zero");
} catch (IllegalArgumentException expected) {
}
try {
a1 = new AcceptorImpl(port1, null, false, CacheServer.DEFAULT_SOCKET_BUFFER_SIZE, CacheServer.DEFAULT_MAXIMUM_TIME_BETWEEN_PINGS, this.cache, AcceptorImpl.MINIMUM_MAX_CONNECTIONS, CacheServer.DEFAULT_MAX_THREADS, CacheServer.DEFAULT_MAXIMUM_MESSAGE_COUNT, CacheServer.DEFAULT_MESSAGE_TIME_TO_LIVE, null, null, false, Collections.EMPTY_LIST, CacheServer.DEFAULT_TCP_NO_DELAY);
a2 = new AcceptorImpl(port1, null, false, CacheServer.DEFAULT_SOCKET_BUFFER_SIZE, CacheServer.DEFAULT_MAXIMUM_TIME_BETWEEN_PINGS, this.cache, AcceptorImpl.MINIMUM_MAX_CONNECTIONS, CacheServer.DEFAULT_MAX_THREADS, CacheServer.DEFAULT_MAXIMUM_MESSAGE_COUNT, CacheServer.DEFAULT_MESSAGE_TIME_TO_LIVE, null, null, false, Collections.EMPTY_LIST, CacheServer.DEFAULT_TCP_NO_DELAY);
fail("Expecetd a BindException while attaching to the same port");
} catch (BindException expected) {
}
a3 = new AcceptorImpl(port2, null, false, CacheServer.DEFAULT_SOCKET_BUFFER_SIZE, CacheServer.DEFAULT_MAXIMUM_TIME_BETWEEN_PINGS, this.cache, AcceptorImpl.MINIMUM_MAX_CONNECTIONS, CacheServer.DEFAULT_MAX_THREADS, CacheServer.DEFAULT_MAXIMUM_MESSAGE_COUNT, CacheServer.DEFAULT_MESSAGE_TIME_TO_LIVE, null, null, false, Collections.EMPTY_LIST, CacheServer.DEFAULT_TCP_NO_DELAY);
assertEquals(port2, a3.getPort());
InternalDistributedSystem isystem = (InternalDistributedSystem) this.cache.getDistributedSystem();
DistributionConfig config = isystem.getConfig();
String bindAddress = config.getBindAddress();
if (bindAddress == null || bindAddress.length() <= 0) {
assertTrue(a3.getServerInetAddr().isAnyLocalAddress());
}
} finally {
if (a1 != null)
a1.close();
if (a2 != null)
a2.close();
if (a3 != null)
a3.close();
}
}
use of org.apache.geode.distributed.internal.DistributionConfig in project geode by apache.
the class DistributedSystemLogFileJUnitTest method testDistributedSystemWithSecurityLogDefaultLevel.
@Test
public void testDistributedSystemWithSecurityLogDefaultLevel() throws Exception {
// final int port = AvailablePort.getRandomAvailablePort(AvailablePort.JGROUPS);
final String logFileName = name.getMethodName() + "-system-" + System.currentTimeMillis() + ".log";
final String securityLogFileName = "security" + name.getMethodName() + "-system-" + System.currentTimeMillis() + ".log";
final Properties properties = new Properties();
properties.put(LOG_FILE, logFileName);
properties.put(LOG_LEVEL, "fine");
properties.put(SECURITY_LOG_FILE, securityLogFileName);
properties.put(MCAST_PORT, "0");
properties.put(LOCATORS, "");
properties.put(ENABLE_NETWORK_PARTITION_DETECTION, "false");
properties.put(DISABLE_AUTO_RECONNECT, "true");
properties.put(MEMBER_TIMEOUT, "2000");
properties.put(ENABLE_CLUSTER_CONFIGURATION, "false");
final File securityLogFile = new File(securityLogFileName);
if (securityLogFile.exists()) {
securityLogFile.delete();
}
assertFalse(securityLogFile.exists());
final File logFile = new File(logFileName);
if (logFile.exists()) {
logFile.delete();
}
assertFalse(logFile.exists());
this.system = DistributedSystem.connect(properties);
assertNotNull(this.system);
DistributionConfig config = ((InternalDistributedSystem) this.system).getConfig();
assertEquals("Expected " + LogWriterImpl.levelToString(InternalLogWriter.CONFIG_LEVEL) + " but was " + LogWriterImpl.levelToString(config.getLogLevel()), InternalLogWriter.CONFIG_LEVEL, config.getSecurityLogLevel());
assertEquals("Expected " + LogWriterImpl.levelToString(InternalLogWriter.FINE_LEVEL) + " but was " + LogWriterImpl.levelToString(config.getLogLevel()), InternalLogWriter.FINE_LEVEL, config.getLogLevel());
InternalLogWriter securityLogWriter = (InternalLogWriter) system.getSecurityLogWriter();
InternalLogWriter logWriter = (InternalLogWriter) system.getLogWriter();
assertNotNull(securityLogWriter);
assertNotNull(logWriter);
assertTrue(securityLogWriter instanceof LogWriterLogger);
assertTrue(logWriter instanceof LogWriterLogger);
assertEquals("Expected " + LogWriterImpl.levelToString(InternalLogWriter.INFO_LEVEL) + " but was " + LogWriterImpl.levelToString(securityLogWriter.getLogWriterLevel()), InternalLogWriter.INFO_LEVEL, securityLogWriter.getLogWriterLevel());
assertEquals("Expected " + LogWriterImpl.levelToString(InternalLogWriter.FINE_LEVEL) + " but was " + LogWriterImpl.levelToString(securityLogWriter.getLogWriterLevel()), InternalLogWriter.FINE_LEVEL, logWriter.getLogWriterLevel());
assertFalse(securityLogWriter.fineEnabled());
assertTrue(logWriter.fineEnabled());
assertFalse(((LogWriterLogger) securityLogWriter).isDebugEnabled());
assertTrue(((LogWriterLogger) logWriter).isDebugEnabled());
assertTrue(securityLogWriter instanceof FastLogger);
assertTrue(logWriter instanceof FastLogger);
// Because debug available is a static volatile, it is shared between the two writers
// However we should not see any debug level logging due to the config level set in
// the log writer itself
assertTrue(((FastLogger) securityLogWriter).isDelegating());
assertTrue(((FastLogger) logWriter).isDelegating());
Wait.waitForCriterion(new WaitCriterion() {
@Override
public boolean done() {
return securityLogFile.exists() && logFile.exists();
}
@Override
public String description() {
return "waiting for log files to exist: " + securityLogFile + ", " + logFile;
}
}, TIMEOUT_MILLISECONDS, INTERVAL_MILLISECONDS, true);
assertTrue(securityLogFile.exists());
assertTrue(logFile.exists());
securityLogWriter.info("test: security log file created at info");
// assert not empty
FileInputStream fis = new FileInputStream(securityLogFile);
try {
assertTrue(fis.available() > 0);
} finally {
fis.close();
}
final Logger logger = LogService.getLogger();
int i = 0;
{
i++;
final String FINEST_STRING = "testLogLevels Message logged at FINEST level [" + i + "]";
securityLogWriter.finest(FINEST_STRING);
assertFalse(fileContainsString(securityLogFile, FINEST_STRING));
assertFalse(fileContainsString(logFile, FINEST_STRING));
i++;
final String FINE_STRING = "testLogLevels Message logged at FINE level [" + i + "]";
securityLogWriter.fine(FINE_STRING);
assertFalse(fileContainsString(securityLogFile, FINE_STRING));
assertFalse(fileContainsString(logFile, FINE_STRING));
i++;
final String INFO_STRING = "testLogLevels Message logged at INFO level [" + i + "]";
securityLogWriter.info(INFO_STRING);
assertTrue(fileContainsString(securityLogFile, INFO_STRING));
assertFalse(fileContainsString(logFile, INFO_STRING));
i++;
final String FINE_STRING_FOR_LOGGER = "testLogLevels Message logged at FINE level [" + i + "]";
logger.debug(FINE_STRING_FOR_LOGGER);
assertFalse(fileContainsString(securityLogFile, FINE_STRING_FOR_LOGGER));
assertTrue(fileContainsString(logFile, FINE_STRING_FOR_LOGGER));
}
this.system.disconnect();
this.system = null;
}
use of org.apache.geode.distributed.internal.DistributionConfig in project geode by apache.
the class DistributedSystemLogFileJUnitTest method testDistributedSystemWithSecurityLogFineLevel.
@Test
public void testDistributedSystemWithSecurityLogFineLevel() throws Exception {
// final int port = AvailablePort.getRandomAvailablePort(AvailablePort.JGROUPS);
final String logFileName = name.getMethodName() + "-system-" + System.currentTimeMillis() + ".log";
final String securityLogFileName = "security" + name.getMethodName() + "-system-" + System.currentTimeMillis() + ".log";
final Properties properties = new Properties();
properties.put(LOG_FILE, logFileName);
properties.put(LOG_LEVEL, "fine");
properties.put(SECURITY_LOG_FILE, securityLogFileName);
properties.put(SECURITY_LOG_LEVEL, "fine");
properties.put(MCAST_PORT, "0");
properties.put(LOCATORS, "");
properties.put(ENABLE_NETWORK_PARTITION_DETECTION, "false");
properties.put(DISABLE_AUTO_RECONNECT, "true");
properties.put(MEMBER_TIMEOUT, "2000");
properties.put(ENABLE_CLUSTER_CONFIGURATION, "false");
final File securityLogFile = new File(securityLogFileName);
if (securityLogFile.exists()) {
securityLogFile.delete();
}
assertFalse(securityLogFile.exists());
final File logFile = new File(logFileName);
if (logFile.exists()) {
logFile.delete();
}
assertFalse(logFile.exists());
this.system = DistributedSystem.connect(properties);
assertNotNull(this.system);
DistributionConfig config = ((InternalDistributedSystem) this.system).getConfig();
assertEquals("Expected " + LogWriterImpl.levelToString(InternalLogWriter.FINE_LEVEL) + " but was " + LogWriterImpl.levelToString(config.getLogLevel()), InternalLogWriter.FINE_LEVEL, config.getSecurityLogLevel());
assertEquals("Expected " + LogWriterImpl.levelToString(InternalLogWriter.FINE_LEVEL) + " but was " + LogWriterImpl.levelToString(config.getLogLevel()), InternalLogWriter.FINE_LEVEL, config.getLogLevel());
InternalLogWriter securityLogWriter = (InternalLogWriter) system.getSecurityLogWriter();
InternalLogWriter logWriter = (InternalLogWriter) system.getLogWriter();
assertNotNull(securityLogWriter);
assertNotNull(logWriter);
assertTrue(securityLogWriter instanceof LogWriterLogger);
assertTrue(logWriter instanceof LogWriterLogger);
assertEquals("Expected " + LogWriterImpl.levelToString(InternalLogWriter.FINE_LEVEL) + " but was " + LogWriterImpl.levelToString(securityLogWriter.getLogWriterLevel()), InternalLogWriter.FINE_LEVEL, securityLogWriter.getLogWriterLevel());
assertEquals("Expected " + LogWriterImpl.levelToString(InternalLogWriter.FINE_LEVEL) + " but was " + LogWriterImpl.levelToString(securityLogWriter.getLogWriterLevel()), InternalLogWriter.FINE_LEVEL, logWriter.getLogWriterLevel());
assertTrue(securityLogWriter.fineEnabled());
assertTrue(logWriter.fineEnabled());
assertTrue(((LogWriterLogger) securityLogWriter).isDebugEnabled());
assertTrue(((LogWriterLogger) logWriter).isDebugEnabled());
assertTrue(securityLogWriter instanceof FastLogger);
assertTrue(logWriter instanceof FastLogger);
assertTrue(((FastLogger) securityLogWriter).isDelegating());
assertTrue(((FastLogger) logWriter).isDelegating());
Wait.waitForCriterion(new WaitCriterion() {
@Override
public boolean done() {
return securityLogFile.exists() && logFile.exists();
}
@Override
public String description() {
return "waiting for log files to exist: " + securityLogFile + ", " + logFile;
}
}, TIMEOUT_MILLISECONDS, INTERVAL_MILLISECONDS, true);
assertTrue(securityLogFile.exists());
assertTrue(logFile.exists());
// assert not empty
FileInputStream fis = new FileInputStream(securityLogFile);
try {
assertTrue(fis.available() > 0);
} finally {
fis.close();
}
final Logger logger = LogService.getLogger();
int i = 0;
{
i++;
final String FINEST_STRING = "testLogLevels Message logged at FINEST level [" + i + "]";
securityLogWriter.finest(FINEST_STRING);
assertFalse(fileContainsString(securityLogFile, FINEST_STRING));
assertFalse(fileContainsString(logFile, FINEST_STRING));
i++;
final String FINER_STRING = "testLogLevels Message logged at FINER level [" + i + "]";
securityLogWriter.finer(FINER_STRING);
assertFalse(fileContainsString(securityLogFile, FINER_STRING));
assertFalse(fileContainsString(logFile, FINER_STRING));
i++;
final String FINE_STRING = "testLogLevels Message logged at FINE level [" + i + "]";
securityLogWriter.fine(FINE_STRING);
assertTrue(fileContainsString(securityLogFile, FINE_STRING));
assertFalse(fileContainsString(logFile, FINE_STRING));
i++;
final String CONFIG_STRING = "testLogLevels Message logged at CONFIG level [" + i + "]";
securityLogWriter.config(CONFIG_STRING);
assertTrue(fileContainsString(securityLogFile, CONFIG_STRING));
assertFalse(fileContainsString(logFile, CONFIG_STRING));
i++;
final String INFO_STRING = "testLogLevels Message logged at INFO level [" + i + "]";
securityLogWriter.info(INFO_STRING);
assertTrue(fileContainsString(securityLogFile, INFO_STRING));
assertFalse(fileContainsString(logFile, INFO_STRING));
i++;
final String WARNING_STRING = "ExpectedStrings: testLogLevels Message logged at WARNING level [" + i + "]";
securityLogWriter.warning(WARNING_STRING);
assertTrue(fileContainsString(securityLogFile, WARNING_STRING));
assertFalse(fileContainsString(logFile, WARNING_STRING));
i++;
final String ERROR_STRING = "ExpectedStrings: testLogLevels Message logged at ERROR level [" + i + "]";
securityLogWriter.error(ERROR_STRING);
assertTrue(fileContainsString(securityLogFile, ERROR_STRING));
assertFalse(fileContainsString(logFile, ERROR_STRING));
i++;
final String SEVERE_STRING = "ExpectedStrings: testLogLevels Message logged at SEVERE level [" + i + "]";
securityLogWriter.severe(SEVERE_STRING);
assertTrue(fileContainsString(securityLogFile, SEVERE_STRING));
assertFalse(fileContainsString(logFile, SEVERE_STRING));
i++;
final String TRACE_STRING = "testLogLevels Message logged at TRACE level [" + i + "]";
logger.trace(TRACE_STRING);
assertFalse(fileContainsString(securityLogFile, TRACE_STRING));
assertFalse(fileContainsString(logFile, TRACE_STRING));
i++;
final String DEBUG_STRING = "testLogLevels Message logged at DEBUG level [" + i + "]";
logger.debug(DEBUG_STRING);
assertFalse(fileContainsString(securityLogFile, DEBUG_STRING));
assertTrue(fileContainsString(logFile, DEBUG_STRING));
i++;
final String INFO_STRING_J = "testLogLevels Message logged at INFO level [" + i + "]";
logger.info(INFO_STRING_J);
assertFalse(fileContainsString(securityLogFile, INFO_STRING_J));
assertTrue(fileContainsString(logFile, INFO_STRING_J));
i++;
final String WARN_STRING = "ExpectedStrings: testLogLevels Message logged at WARN level [" + i + "]";
logger.warn(WARN_STRING);
assertFalse(fileContainsString(securityLogFile, WARN_STRING));
assertTrue(fileContainsString(logFile, WARN_STRING));
i++;
final String ERROR_STRING_J = "ExpectedStrings: testLogLevels Message logged at ERROR level [" + i + "]";
logger.error(ERROR_STRING_J);
assertFalse(fileContainsString(securityLogFile, ERROR_STRING_J));
assertTrue(fileContainsString(logFile, ERROR_STRING_J));
i++;
final String FATAL_STRING = "ExpectedStrings: testLogLevels Message logged at FATAL level [" + i + "]";
logger.fatal(FATAL_STRING);
assertFalse(fileContainsString(securityLogFile, FATAL_STRING));
assertTrue(fileContainsString(logFile, FATAL_STRING));
}
this.system.disconnect();
this.system = null;
}
Aggregations