use of com.sun.identity.shared.debug.file.impl.DebugConfigurationFromProperties in project OpenAM by OpenRock.
the class DebugConfigurationFromPropertiesTest method sizeRotationConfig.
@Test
public void sizeRotationConfig() throws Exception {
DebugConfigurationFromProperties debugConfigurationFromProperties = new DebugConfigurationFromProperties(DEBUG_CONFIG_DIRECTORY + "valid/sizeRotationConfig.properties");
Assert.assertTrue(debugConfigurationFromProperties.getDebugPrefix().isEmpty(), "Debug prefix should be empty");
Assert.assertEquals(debugConfigurationFromProperties.getDebugSuffix(), "-MM.dd.yyyy-HH.mm.ss.SSS");
Assert.assertEquals(debugConfigurationFromProperties.getRotationInterval(), -1, "Debug rotation should be " + "empty");
Assert.assertEquals(debugConfigurationFromProperties.getRotationFileSizeInByte(), 2 << 20);
}
use of com.sun.identity.shared.debug.file.impl.DebugConfigurationFromProperties in project OpenAM by OpenRock.
the class DebugRotationTest method rotation.
private void rotation(long fakeInitTime) throws Exception {
String DEBUG_CONFIG_FOR_TEST = "/debug_config_test/debugconfigRotation.properties";
DebugConfigurationFromProperties debugConfigurationFromProperties = new DebugConfigurationFromProperties(DEBUG_CONFIG_FOR_TEST);
initializeProperties();
initializeProvider(DEBUG_CONFIG_FOR_TEST);
//initialize a scenario
SimpleDateFormat dateFormat = new SimpleDateFormat("-MM.dd.yyyy-HH.mm");
String debugNameFile = "debugMerge";
int rotationPeriod = debugConfigurationFromProperties.getRotationInterval();
//Accelerate the test timeservice
// Simulate 1 hours of logs
int fakeDurationMs = 60 * 60 * 1000;
//In order to have an effective and short in time test, we accelerate the time
AccelerateTimeService accelerateClock = new AccelerateTimeService(fakeInitTime);
debugFileProvider.setClock(accelerateClock);
// check debugFiles.properties to see the mapping
IDebug debugTest1MergeToDebugMerge = provider.getInstance("debugTest1MergeToDebugMerge");
IDebug debugTest2MergeToDebugMerge = provider.getInstance("debugTest2MergeToDebugMerge");
IDebug debugTest3MergeToDebugMerge = provider.getInstance("debugTest3MergeToDebugMerge");
// We will print on logs from threads, for testing the synchronized
List<PrintLogRunnable> printLogRunnableTests = new ArrayList<PrintLogRunnable>();
PrintLogRunnable printLogRunnableTest1 = new PrintLogRunnable(debugTest1MergeToDebugMerge, fakeInitTime, fakeDurationMs, accelerateClock);
printLogRunnableTests.add(printLogRunnableTest1);
PrintLogRunnable printLogRunnableTest2 = new PrintLogRunnable(debugTest2MergeToDebugMerge, fakeInitTime, fakeDurationMs, accelerateClock);
printLogRunnableTests.add(printLogRunnableTest2);
PrintLogRunnable printLogRunnableTest3 = new PrintLogRunnable(debugTest3MergeToDebugMerge, fakeInitTime, fakeDurationMs, accelerateClock);
printLogRunnableTests.add(printLogRunnableTest3);
List<Thread> threads = new ArrayList<Thread>();
for (PrintLogRunnable printLogRunnableTest : printLogRunnableTests) {
threads.add(new Thread(printLogRunnableTest));
}
//The first writing initialize the log file. So we test that a swift of 1 minute doesn't
//create a new file at the end
debugTest1MergeToDebugMerge.message("Should appear in log", null);
accelerateClock.incrementTime(1000 * 60 + 10);
debugTest2MergeToDebugMerge.message("Should appear in log", null);
accelerateClock.incrementTime(1000 * 60 + 10);
debugTest3MergeToDebugMerge.message("Should appear in log", null);
//Start threads
for (Thread thread : threads) {
thread.start();
}
//Wait threads
for (Thread thread : threads) {
thread.join();
}
//Check if any thread had a exception
for (PrintLogRunnable printLogRunnableTest : printLogRunnableTests) {
if (printLogRunnableTest.ex != null)
throw printLogRunnableTest.ex;
}
//Check files creation
Calendar fakeDate = Calendar.getInstance();
fakeDate.setTimeInMillis(fakeInitTime);
int currentPeriod = -1;
while (fakeDate.getTimeInMillis() - fakeInitTime < fakeDurationMs) {
if (isFileExist(debugNameFile + dateFormat.format(fakeDate.getTime()))) {
if (currentPeriod != -1 && currentPeriod < rotationPeriod) {
failAndPrintFolderStatusReport("A log rotation file is created before the log rotation ended. " + "currentPeriod= '" + currentPeriod + "'");
}
currentPeriod = 0;
}
currentPeriod++;
fakeDate.add(Calendar.MINUTE, 1);
}
}
use of com.sun.identity.shared.debug.file.impl.DebugConfigurationFromProperties in project OpenAM by OpenRock.
the class DebugConfigurationFromPropertiesTest method timeRotationConfig.
@Test
public void timeRotationConfig() throws Exception {
DebugConfigurationFromProperties debugConfigurationFromProperties = new DebugConfigurationFromProperties(DEBUG_CONFIG_DIRECTORY + "valid/timeRotationConfig.properties");
Assert.assertTrue(debugConfigurationFromProperties.getDebugPrefix().isEmpty(), "Debug prefix should be empty");
Assert.assertEquals(debugConfigurationFromProperties.getDebugSuffix(), "-MM.dd.yyyy-HH.mm");
Assert.assertEquals(debugConfigurationFromProperties.getRotationInterval(), 3);
Assert.assertEquals(debugConfigurationFromProperties.getRotationFileSizeInByte(), -1, "Debug file size " + "rotation should be empty");
}
use of com.sun.identity.shared.debug.file.impl.DebugConfigurationFromProperties in project OpenAM by OpenRock.
the class DebugConfigurationFromPropertiesTest method prefixConfig.
@Test
public void prefixConfig() throws Exception {
DebugConfigurationFromProperties debugConfigurationFromProperties = new DebugConfigurationFromProperties(DEBUG_CONFIG_DIRECTORY + "valid/prefixconfig.properties");
Assert.assertEquals(debugConfigurationFromProperties.getDebugPrefix(), "openam_");
Assert.assertTrue(debugConfigurationFromProperties.getDebugSuffix().isEmpty(), "Debug suffix should be empty");
Assert.assertEquals(debugConfigurationFromProperties.getRotationInterval(), -1, "Debug rotation should be " + "empty");
Assert.assertEquals(debugConfigurationFromProperties.getRotationFileSizeInByte(), -1, "Debug file size " + "rotation should be empty");
}
use of com.sun.identity.shared.debug.file.impl.DebugConfigurationFromProperties in project OpenAM by OpenRock.
the class DebugConfigurationFromPropertiesTest method basicConfig.
/*
* Valid configuration
*/
@Test
public void basicConfig() throws Exception {
DebugConfigurationFromProperties debugConfigurationFromProperties = new DebugConfigurationFromProperties(DEBUG_CONFIG_DIRECTORY + "valid/basicconfig.properties");
Assert.assertTrue(debugConfigurationFromProperties.getDebugPrefix().isEmpty(), "Debug prefix should be empty");
Assert.assertEquals(debugConfigurationFromProperties.getDebugSuffix(), "-MM.dd.yyyy-HH.mm");
Assert.assertEquals(debugConfigurationFromProperties.getRotationInterval(), -1, "Debug rotation should be " + "empty");
Assert.assertEquals(debugConfigurationFromProperties.getRotationFileSizeInByte(), -1, "Debug file size " + "rotation should be empty");
}
Aggregations