Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnjum Fatima2019-01-09 12:50:37 -0500
committerThomas Watson2019-01-11 09:28:24 -0500
commit0799bffaa7c6b44c79bf044511c7fcdfc2e096de (patch)
tree09c4d1197f027fe3037bcd3fb23339eb81623111
parentbbccd4175ebd9df8c3ae41086c51fd8b0a219650 (diff)
downloadrt.equinox.framework-0799bffaa7c6b44c79bf044511c7fcdfc2e096de.tar.gz
rt.equinox.framework-0799bffaa7c6b44c79bf044511c7fcdfc2e096de.tar.xz
rt.equinox.framework-0799bffaa7c6b44c79bf044511c7fcdfc2e096de.zip
STARTING/STOPPING bundle event Change-Id: I44ca2127c8ac1a8f1336d64c0f541e208f2cced8 Signed-off-by: Anjum Fatima <anjum.eclipse@gmail.com>
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/ExtendedLogReaderServiceTest.java20
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/ExtendedLogServiceTest.java45
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/LogReaderServiceTest.java79
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/LogServiceTest.java109
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/TestListener.java44
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/LogServiceManager.java6
6 files changed, 111 insertions, 192 deletions
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/ExtendedLogReaderServiceTest.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/ExtendedLogReaderServiceTest.java
index 48a91ec04..6e27a6494 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/ExtendedLogReaderServiceTest.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/ExtendedLogReaderServiceTest.java
@@ -77,10 +77,7 @@ public class ExtendedLogReaderServiceTest extends TestCase {
return true;
}
});
- synchronized (listener) {
- log.log(LogService.LOG_INFO, "info");
- listener.waitForLogEntry();
- }
+ log.log(LogService.LOG_INFO, "info");
assertTrue(listener.getEntryX().getLevel() == LogService.LOG_INFO);
}
@@ -111,10 +108,7 @@ public class ExtendedLogReaderServiceTest extends TestCase {
return true;
}
});
- synchronized (listener) {
- log.log(LogService.LOG_INFO, "info");
- listener.waitForLogEntry();
- }
+ log.log(LogService.LOG_INFO, "info");
assertTrue(listener.getEntryX().getLevel() == LogService.LOG_INFO);
}
@@ -159,17 +153,11 @@ public class ExtendedLogReaderServiceTest extends TestCase {
long timeBeforeLog = System.currentTimeMillis();
String threadName = Thread.currentThread().getName();
long threadId = getCurrentThreadId();
- synchronized (listener) {
- log.getLogger("test").log(logReference, LogService.LOG_INFO, "info", new Throwable("test"));
- listener.waitForLogEntry();
- }
+ log.getLogger("test").log(logReference, LogService.LOG_INFO, "info", new Throwable("test"));
ExtendedLogEntry entry = listener.getEntryX();
long sequenceNumberBefore = entry.getSequenceNumber();
- synchronized (listener) {
- log.getLogger("test").log(logReference, LogService.LOG_INFO, "info", new Throwable("test"));
- listener.waitForLogEntry();
- }
+ log.getLogger("test").log(logReference, LogService.LOG_INFO, "info", new Throwable("test"));
entry = listener.getEntryX();
assertTrue(entry.getBundle() == OSGiTestsActivator.getContext().getBundle());
assertTrue(entry.getMessage().equals("info"));
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/ExtendedLogServiceTest.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/ExtendedLogServiceTest.java
index 37b5e88ad..f71de4be6 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/ExtendedLogServiceTest.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/ExtendedLogServiceTest.java
@@ -15,7 +15,10 @@ package org.eclipse.equinox.log.test;
import java.util.HashMap;
import java.util.Map;
import junit.framework.TestCase;
-import org.eclipse.equinox.log.*;
+import org.eclipse.equinox.log.ExtendedLogEntry;
+import org.eclipse.equinox.log.ExtendedLogReaderService;
+import org.eclipse.equinox.log.ExtendedLogService;
+import org.eclipse.equinox.log.LogFilter;
import org.eclipse.osgi.tests.OSGiTestsActivator;
import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceReference;
@@ -73,26 +76,17 @@ public class ExtendedLogServiceTest extends TestCase {
}
public void testLogContext() throws Exception {
- synchronized (listener) {
- log.log(this, LogService.LOG_INFO, null);
- listener.waitForLogEntry();
- }
+ log.log(this, LogService.LOG_INFO, null);
assertTrue(listener.getEntryX().getContext() == this);
}
public void testNullLogContext() throws Exception {
- synchronized (listener) {
- log.log(null, LogService.LOG_INFO, null);
- listener.waitForLogEntry();
- }
+ log.log(null, LogService.LOG_INFO, null);
assertTrue(listener.getEntryX().getContext() == null);
}
public void testLogContextWithNullThrowable() throws Exception {
- synchronized (listener) {
- log.log(this, LogService.LOG_INFO, null, null);
- listener.waitForLogEntry();
- }
+ log.log(this, LogService.LOG_INFO, null, null);
assertTrue(listener.getEntryX().getContext() == this);
}
@@ -119,10 +113,7 @@ public class ExtendedLogServiceTest extends TestCase {
}
public void testNamedLoggerLogNull() throws Exception {
- synchronized (listener) {
- log.getLogger("test").log(null, 0, null, null);
- listener.waitForLogEntry();
- }
+ log.getLogger("test").log(null, 0, null, null);
ExtendedLogEntry entry = listener.getEntryX();
assertTrue(entry.getLoggerName() == "test");
assertTrue(entry.getLevel() == 0);
@@ -132,10 +123,7 @@ public class ExtendedLogServiceTest extends TestCase {
}
public void testNullLoggerLogNull() throws Exception {
- synchronized (listener) {
- log.getLogger((String) null).log(null, 0, null, null);
- listener.waitForLogEntry();
- }
+ log.getLogger((String) null).log(null, 0, null, null);
ExtendedLogEntry entry = listener.getEntryX();
assertEquals("Wrong logger name.", "LogService", entry.getLoggerName());
assertTrue(entry.getLevel() == 0);
@@ -147,10 +135,7 @@ public class ExtendedLogServiceTest extends TestCase {
public void testNamedLoggerLogFull() throws Exception {
String message = "test";
Throwable t = new Throwable("test");
- synchronized (listener) {
- log.getLogger("test").log(logReference, LogService.LOG_INFO, message, t);
- listener.waitForLogEntry();
- }
+ log.getLogger("test").log(logReference, LogService.LOG_INFO, message, t);
ExtendedLogEntry entry = listener.getEntryX();
assertTrue(entry.getLoggerName() == "test");
assertTrue(entry.getBundle() == bundle);
@@ -163,10 +148,7 @@ public class ExtendedLogServiceTest extends TestCase {
public void testNamedLoggerLogFullWithNullBundle() throws Exception {
String message = "test";
Throwable t = new Throwable("test");
- synchronized (listener) {
- log.getLogger(null, "test").log(logReference, LogService.LOG_INFO, message, t);
- listener.waitForLogEntry();
- }
+ log.getLogger(null, "test").log(logReference, LogService.LOG_INFO, message, t);
ExtendedLogEntry entry = listener.getEntryX();
assertTrue(entry.getLoggerName() == "test");
assertTrue(entry.getBundle() == bundle);
@@ -179,10 +161,7 @@ public class ExtendedLogServiceTest extends TestCase {
public void testNamedLoggerLogFullWithBundle() throws Exception {
String message = "test";
Throwable t = new Throwable("test");
- synchronized (listener) {
- log.getLogger(bundle, "test").log(logReference, LogService.LOG_INFO, message, t);
- listener.waitForLogEntry();
- }
+ log.getLogger(bundle, "test").log(logReference, LogService.LOG_INFO, message, t);
ExtendedLogEntry entry = listener.getEntryX();
assertTrue(entry.getLoggerName() == "test");
assertTrue(entry.getBundle() == bundle);
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/LogReaderServiceTest.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/LogReaderServiceTest.java
index aa1426bea..4d3f62d3d 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/LogReaderServiceTest.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/LogReaderServiceTest.java
@@ -91,10 +91,7 @@ public class LogReaderServiceTest extends AbstractBundleTests {
public void testaddListener() throws Exception {
TestListener listener = new TestListener();
reader.addLogListener(listener);
- synchronized (listener) {
- log.log(LogService.LOG_INFO, "info"); //$NON-NLS-1$
- listener.waitForLogEntry();
- }
+ log.log(LogService.LOG_INFO, "info"); //$NON-NLS-1$
assertTrue(listener.getEntryX().getLevel() == LogService.LOG_INFO);
}
@@ -102,10 +99,7 @@ public class LogReaderServiceTest extends AbstractBundleTests {
TestListener listener = new TestListener();
reader.addLogListener(listener);
reader.addLogListener(listener);
- synchronized (listener) {
- log.log(LogService.LOG_INFO, "info"); //$NON-NLS-1$
- listener.waitForLogEntry();
- }
+ log.log(LogService.LOG_INFO, "info"); //$NON-NLS-1$
assertTrue(listener.getEntryX().getLevel() == LogService.LOG_INFO);
}
@@ -137,10 +131,7 @@ public class LogReaderServiceTest extends AbstractBundleTests {
TestListener listener = new TestListener();
reader.addLogListener(listener);
long timeBeforeLog = System.currentTimeMillis();
- synchronized (listener) {
- log.log(logReference, LogService.LOG_INFO, "info", new Throwable("test")); //$NON-NLS-1$ //$NON-NLS-2$
- listener.waitForLogEntry();
- }
+ log.log(logReference, LogService.LOG_INFO, "info", new Throwable("test")); //$NON-NLS-1$ //$NON-NLS-2$
LogEntry entry = listener.getEntryX();
assertTrue(entry.getBundle() == OSGiTestsActivator.getContext().getBundle());
assertTrue(entry.getMessage().equals("info")); //$NON-NLS-1$
@@ -153,12 +144,10 @@ public class LogReaderServiceTest extends AbstractBundleTests {
public void testLogBundleEventInfo() throws Exception {
// this is just a bundle that is harmless to start/stop
Bundle testBundle = installer.installBundle("test.logging.a"); //$NON-NLS-1$
- TestListener listener = new TestListener(testBundle);
+ TestListener listener = new TestListener(testBundle.getLocation());
reader.addLogListener(listener);
- synchronized (listener) {
- testBundle.start();
- listener.waitForLogEntry();
- }
+
+ testBundle.start();
ExtendedLogEntry entry = listener.getEntryX();
assertTrue(entry.getLevel() == LogService.LOG_INFO);
@@ -188,10 +177,7 @@ public class LogReaderServiceTest extends AbstractBundleTests {
public void testLogServiceEventInfo() throws Exception {
TestListener listener = new TestListener();
reader.addLogListener(listener);
- synchronized (listener) {
- OSGiTestsActivator.getContext().registerService(Object.class.getName(), new Object(), null);
- listener.waitForLogEntry();
- }
+ OSGiTestsActivator.getContext().registerService(Object.class.getName(), new Object(), null);
ExtendedLogEntry entry = listener.getEntryX();
assertTrue(entry.getLevel() == LogService.LOG_INFO);
assertEquals("Wrong level.", LogLevel.INFO, entry.getLogLevel());
@@ -203,10 +189,7 @@ public class LogReaderServiceTest extends AbstractBundleTests {
TestListener listener = new TestListener();
reader.addLogListener(listener);
- synchronized (listener) {
- registration.setProperties(new Hashtable());
- listener.waitForLogEntry();
- }
+ registration.setProperties(new Hashtable());
ExtendedLogEntry entry = listener.getEntryX();
assertTrue(entry.getLevel() == LogService.LOG_DEBUG);
assertEquals("Wrong level.", LogLevel.DEBUG, entry.getLogLevel());
@@ -348,7 +331,7 @@ public class LogReaderServiceTest extends AbstractBundleTests {
//Bundle is installed and a logger is associated with that bundle before setting the log level
setAndAssertLogLevel(bundle.getSymbolicName(), loggerName);
- TestListener listener = new TestListener(bundle);
+ TestListener listener = new TestListener(bundle.getLocation());
reader.addLogListener(listener);
for (LogLevel logLevel : LogLevel.values()) {
String message = logLevel.name() + " MESSAGE";
@@ -372,7 +355,7 @@ public class LogReaderServiceTest extends AbstractBundleTests {
setAndAssertLogLevel(bundle.getSymbolicName(), loggerName);
Logger logger = log.getLogger(bundle, loggerName, Logger.class);
assertNotNull("Logger cannot be null", logger);
- TestListener listener = new TestListener(bundle);
+ TestListener listener = new TestListener(bundle.getLocation());
reader.addLogListener(listener);
for (LogLevel logLevel : LogLevel.values()) {
String message = logLevel.name() + " MESSAGE";
@@ -396,7 +379,7 @@ public class LogReaderServiceTest extends AbstractBundleTests {
bundle.start();
Logger logger = log.getLogger(bundle, loggerName, Logger.class);
assertNotNull("Logger cannot be null", logger);
- TestListener listener = new TestListener(bundle);
+ TestListener listener = new TestListener(bundle.getLocation());
reader.addLogListener(listener);
for (LogLevel logLevel : LogLevel.values()) {
String message = logLevel.name() + " MESSAGE";
@@ -420,10 +403,7 @@ public class LogReaderServiceTest extends AbstractBundleTests {
}
private void doLogging(Bundle bundle, Logger logger, TestListener listener, LogLevel logLevel, String message) throws Exception {
- synchronized (listener) {
- logToLogger(logger, message, logLevel);
- listener.waitForLogEntry();
- }
+ logToLogger(logger, message, logLevel);
ExtendedLogEntry logEntry = listener.getEntryX();
assertEquals("Wrong message logged", message, logEntry.getMessage());
assertEquals("Wrong Log level", logLevel, logEntry.getLogLevel());
@@ -455,4 +435,39 @@ public class LogReaderServiceTest extends AbstractBundleTests {
fail("Unknown Log level");
}
}
+
+ public void testBundleEventsLogged() throws Exception {
+ String testBundleLoc = installer.getBundleLocation("test.logging.a");
+ TestListener listener = new TestListener(testBundleLoc);
+ reader.addLogListener(listener);
+ Bundle bundle = installer.installBundle("test.logging.a");
+
+ bundle.start();
+ bundle.stop();
+ bundle.update();
+ bundle.start();
+ bundle.stop();
+ bundle.uninstall();
+
+ assertBundleEventLog("BundleEvent INSTALLED", bundle, listener);
+ assertBundleEventLog("BundleEvent RESOLVED", bundle, listener);
+ assertBundleEventLog("BundleEvent STARTED", bundle, listener);
+ assertBundleEventLog("BundleEvent STOPPED", bundle, listener);
+ assertBundleEventLog("BundleEvent UNRESOLVED", bundle, listener);
+ assertBundleEventLog("BundleEvent UPDATED", bundle, listener);
+ assertBundleEventLog("BundleEvent RESOLVED", bundle, listener);
+ assertBundleEventLog("BundleEvent STARTED", bundle, listener);
+ assertBundleEventLog("BundleEvent STOPPED", bundle, listener);
+ assertBundleEventLog("BundleEvent UNRESOLVED", bundle, listener);
+ assertBundleEventLog("BundleEvent UNINSTALLED", bundle, listener);
+
+ }
+
+ private void assertBundleEventLog(String message, Bundle bundle, TestListener listener) throws InterruptedException {
+ LogEntry logEntry = listener.getEntryX();
+ assertEquals("Wrong message.", message, logEntry.getMessage());
+ assertEquals("Wrong bundle.", bundle, logEntry.getBundle());
+
+ }
+
}
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/LogServiceTest.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/LogServiceTest.java
index 93a3969fa..5a4f7fa43 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/LogServiceTest.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/LogServiceTest.java
@@ -75,115 +75,73 @@ public class LogServiceTest extends TestCase {
}
public void testLogDebug() throws Exception {
- synchronized (listener) {
- log.log(LogService.LOG_DEBUG, "debug"); //$NON-NLS-1$
- listener.waitForLogEntry();
- }
+ log.log(LogService.LOG_DEBUG, "debug"); //$NON-NLS-1$
assertTrue(listener.getEntryX().getLevel() == LogService.LOG_DEBUG);
}
public void testLogError() throws Exception {
- synchronized (listener) {
- log.log(LogService.LOG_ERROR, "error"); //$NON-NLS-1$
- listener.waitForLogEntry();
- }
+ log.log(LogService.LOG_ERROR, "error"); //$NON-NLS-1$
assertTrue(listener.getEntryX().getLevel() == LogService.LOG_ERROR);
}
public void testLogInfo() throws Exception {
- synchronized (listener) {
- log.log(LogService.LOG_INFO, "info"); //$NON-NLS-1$
- listener.waitForLogEntry();
- }
+ log.log(LogService.LOG_INFO, "info"); //$NON-NLS-1$
assertTrue(listener.getEntryX().getLevel() == LogService.LOG_INFO);
}
public void testLogWarning() throws Exception {
- synchronized (listener) {
- log.log(LogService.LOG_WARNING, "warning"); //$NON-NLS-1$
- listener.waitForLogEntry();
- }
+ log.log(LogService.LOG_WARNING, "warning"); //$NON-NLS-1$
assertTrue(listener.getEntryX().getLevel() == LogService.LOG_WARNING);
}
public void testLogZeroLevel() throws Exception {
- synchronized (listener) {
- log.log(0, "zero"); //$NON-NLS-1$
- listener.waitForLogEntry();
- }
+ log.log(0, "zero"); //$NON-NLS-1$
assertTrue(listener.getEntryX().getLevel() == 0);
}
public void testLogNegativeLevel() throws Exception {
- synchronized (listener) {
- log.log(-1, "negative"); //$NON-NLS-1$
- listener.waitForLogEntry();
- }
+ log.log(-1, "negative"); //$NON-NLS-1$
assertTrue(listener.getEntryX().getLevel() == -1);
}
public void testLogMessage() throws Exception {
- synchronized (listener) {
- log.log(LogService.LOG_INFO, "message"); //$NON-NLS-1$
- listener.waitForLogEntry();
- }
+ log.log(LogService.LOG_INFO, "message"); //$NON-NLS-1$
assertTrue(listener.getEntryX().getMessage().equals("message")); //$NON-NLS-1$
}
public void testLogNullMessage() throws Exception {
- synchronized (listener) {
- log.log(LogService.LOG_INFO, null);
- listener.waitForLogEntry();
- }
+ log.log(LogService.LOG_INFO, null);
assertTrue(listener.getEntryX().getMessage() == null);
}
public void testLogThrowable() throws Exception {
Throwable t = new Throwable("throwable"); //$NON-NLS-1$
- synchronized (listener) {
- log.log(LogService.LOG_INFO, null, t);
- listener.waitForLogEntry();
- }
+ log.log(LogService.LOG_INFO, null, t);
assertTrue(listener.getEntryX().getException().getMessage().equals(t.getMessage()));
}
public void testLogNullThrowable() throws Exception {
- synchronized (listener) {
- log.log(LogService.LOG_INFO, null, null);
- listener.waitForLogEntry();
- }
+ log.log(LogService.LOG_INFO, null, null);
assertTrue(listener.getEntryX().getException() == null);
}
public void testLogServiceReference() throws Exception {
- synchronized (listener) {
- log.log(logReference, LogService.LOG_INFO, null);
- listener.waitForLogEntry();
- }
+ log.log(logReference, LogService.LOG_INFO, null);
assertTrue(listener.getEntryX().getServiceReference().equals(logReference));
}
public void testNullLogServiceReference() throws Exception {
- synchronized (listener) {
- log.log(null, LogService.LOG_INFO, null);
- listener.waitForLogEntry();
- }
+ log.log(null, LogService.LOG_INFO, null);
assertTrue(listener.getEntryX().getServiceReference() == null);
}
public void testLogServiceReferenceWithNullThrowable() throws Exception {
- synchronized (listener) {
- log.log(logReference, LogService.LOG_INFO, null, null);
- listener.waitForLogEntry();
- }
+ log.log(logReference, LogService.LOG_INFO, null, null);
assertTrue(listener.getEntryX().getServiceReference().equals(logReference));
}
public void testLogNull1() throws Exception {
- synchronized (listener) {
- log.log(0, null);
- listener.waitForLogEntry();
- }
+ log.log(0, null);
LogEntry entry = listener.getEntryX();
assertTrue(entry.getLevel() == 0);
assertTrue(entry.getMessage() == null);
@@ -192,10 +150,7 @@ public class LogServiceTest extends TestCase {
}
public void testLogNull2() throws Exception {
- synchronized (listener) {
- log.log(0, null, null);
- listener.waitForLogEntry();
- }
+ log.log(0, null, null);
LogEntry entry = listener.getEntryX();
assertTrue(entry.getLevel() == 0);
assertTrue(entry.getMessage() == null);
@@ -204,10 +159,7 @@ public class LogServiceTest extends TestCase {
}
public void testLogNull3() throws Exception {
- synchronized (listener) {
- log.log(null, 0, null);
- listener.waitForLogEntry();
- }
+ log.log(null, 0, null);
LogEntry entry = listener.getEntryX();
assertTrue(entry.getLevel() == 0);
assertTrue(entry.getMessage() == null);
@@ -216,10 +168,7 @@ public class LogServiceTest extends TestCase {
}
public void testLogNull4() throws Exception {
- synchronized (listener) {
- log.log(null, 0, null, null);
- listener.waitForLogEntry();
- }
+ log.log(null, 0, null, null);
LogEntry entry = listener.getEntryX();
assertTrue(entry.getLevel() == 0);
assertTrue(entry.getMessage() == null);
@@ -229,10 +178,7 @@ public class LogServiceTest extends TestCase {
public void testLogFull1() throws Exception {
String message = "test"; //$NON-NLS-1$
- synchronized (listener) {
- log.log(LogService.LOG_INFO, message);
- listener.waitForLogEntry();
- }
+ log.log(LogService.LOG_INFO, message);
LogEntry entry = listener.getEntryX();
assertTrue(entry.getLevel() == LogService.LOG_INFO);
assertTrue(entry.getMessage().equals(message));
@@ -243,10 +189,7 @@ public class LogServiceTest extends TestCase {
public void testLogFull2() throws Exception {
String message = "test"; //$NON-NLS-1$
Throwable t = new Throwable("test"); //$NON-NLS-1$
- synchronized (listener) {
- log.log(LogService.LOG_INFO, message, t);
- listener.waitForLogEntry();
- }
+ log.log(LogService.LOG_INFO, message, t);
LogEntry entry = listener.getEntryX();
assertTrue(entry.getLevel() == LogService.LOG_INFO);
assertTrue(entry.getMessage().equals(message));
@@ -256,10 +199,7 @@ public class LogServiceTest extends TestCase {
public void testLogFull3() throws Exception {
String message = "test"; //$NON-NLS-1$
- synchronized (listener) {
- log.log(logReference, LogService.LOG_INFO, message);
- listener.waitForLogEntry();
- }
+ log.log(logReference, LogService.LOG_INFO, message);
LogEntry entry = listener.getEntryX();
assertTrue(entry.getLevel() == LogService.LOG_INFO);
assertTrue(entry.getMessage().equals(message));
@@ -270,10 +210,7 @@ public class LogServiceTest extends TestCase {
public void testLogFull4() throws Exception {
String message = "test"; //$NON-NLS-1$
Throwable t = new Throwable("test"); //$NON-NLS-1$
- synchronized (listener) {
- log.log(logReference, LogService.LOG_INFO, message, t);
- listener.waitForLogEntry();
- }
+ log.log(logReference, LogService.LOG_INFO, message, t);
LogEntry entry = listener.getEntryX();
assertTrue(entry.getLevel() == LogService.LOG_INFO);
assertTrue(entry.getMessage().equals(message));
@@ -285,9 +222,7 @@ public class LogServiceTest extends TestCase {
BundleContext context = OSGiTestsActivator.getContext();
ServiceRegistration<Object> reg = context.registerService(Object.class, new Object(), null);
ServiceReference<Object> ref = reg.getReference();
- listener.waitForLogEntry();
- listener.waitForLogEntry();
LogEntry entry = listener.getEntryX();
assertEquals("Wrong logger name.", "Events.Service", entry.getLoggerName());
assertEquals("Wrong event log level.", LogLevel.INFO, entry.getLogLevel());
@@ -298,7 +233,6 @@ public class LogServiceTest extends TestCase {
reg.setProperties(new Hashtable(Collections.singletonMap("key1", "value1")));
- listener.waitForLogEntry();
entry = listener.getEntryX();
assertEquals("Wrong logger name.", "Events.Service", entry.getLoggerName());
assertEquals("Wrong event log level.", LogLevel.DEBUG, entry.getLogLevel());
@@ -308,7 +242,6 @@ public class LogServiceTest extends TestCase {
assertEquals("Wrong message.", "ServiceEvent MODIFIED", entry.getMessage());
reg.unregister();
- listener.waitForLogEntry();
entry = listener.getEntryX();
assertEquals("Wrong logger name.", "Events.Service", entry.getLoggerName());
assertEquals("Wrong event log level.", LogLevel.INFO, entry.getLogLevel());
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/TestListener.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/TestListener.java
index b468e4d71..bb9cb8946 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/TestListener.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/TestListener.java
@@ -10,49 +10,49 @@ n This program
*******************************************************************************/
package org.eclipse.equinox.log.test;
+import java.util.ArrayList;
+import java.util.List;
import org.eclipse.equinox.log.ExtendedLogEntry;
import org.eclipse.osgi.tests.OSGiTestsActivator;
import org.junit.Assert;
-import org.osgi.framework.Bundle;
import org.osgi.service.log.LogEntry;
import org.osgi.service.log.LogListener;
class TestListener implements LogListener {
- private final Bundle testBundle;
- LogEntry entry;
+ private final String testBundleLoc;
+ private List<LogEntry> logs = new ArrayList<>();
public TestListener() {
this(null);
}
- public TestListener(Bundle testBundle) {
- this.testBundle = testBundle == null ? OSGiTestsActivator.getContext().getBundle() : testBundle;
+ public TestListener(String testBundleLoc) {
+ this.testBundleLoc = testBundleLoc == null ? OSGiTestsActivator.getContext().getBundle().getLocation() : testBundleLoc;
}
public synchronized void logged(LogEntry e) {
- if (!testBundle.equals(e.getBundle()))
+ if (!testBundleLoc.equals(e.getBundle().getLocation())) {
return; // discard logs from all other bundles
- this.entry = e;
+ }
+ logs.add(e);
notifyAll();
}
- public synchronized ExtendedLogEntry getEntryX() {
- ExtendedLogEntry current = (ExtendedLogEntry) entry;
- entry = null;
- return current;
+ public synchronized ExtendedLogEntry getEntryX() throws InterruptedException {
+ return getEntryX(20000);
}
- public void waitForLogEntry() throws InterruptedException {
- synchronized (this) {
- long timeToWait = 20000;
- long startTime = System.currentTimeMillis();
- while (this.entry == null && timeToWait > 0) {
- this.wait(timeToWait);
- timeToWait = timeToWait - (System.currentTimeMillis() - startTime);
- }
- if (this.entry == null) {
- Assert.fail("No log entry logged.");
- }
+ public synchronized ExtendedLogEntry getEntryX(long timeToWait) throws InterruptedException {
+ LogEntry logEntry;
+ long startTime = System.currentTimeMillis();
+ if (logs.size() == 0 && timeToWait > 0) {
+ this.wait(timeToWait);
+ timeToWait = timeToWait - (System.currentTimeMillis() - startTime);
+ }
+ logEntry = logs.size() == 0 ? null : logs.remove(0);
+ if (logEntry == null) {
+ Assert.fail("No log entry logged.");
}
+ return (ExtendedLogEntry) logEntry;
}
} \ No newline at end of file
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/LogServiceManager.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/LogServiceManager.java
index 7f4eca556..79f845b98 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/LogServiceManager.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/LogServiceManager.java
@@ -130,7 +130,11 @@ public class LogServiceManager implements SynchronousBundleListener, FrameworkLi
Bundle bundle = event.getBundle();
if (logReaderServiceFactory.isLoggable(bundle, LOGGER_BUNDLE_EVENT, LogService.LOG_INFO)) {
LoggerImpl logger = (LoggerImpl) systemBundleLog.getLogger(LOGGER_BUNDLE_EVENT);
- logger.log(bundle, event, null, LogService.LOG_INFO, getBundleEventTypeName(event.getType()), null, null);
+ int eventType = event.getType();
+ if (eventType == BundleEvent.STARTING || eventType == BundleEvent.STOPPING || eventType == BundleEvent.LAZY_ACTIVATION) {
+ return;
+ }
+ logger.log(bundle, event, null, LogService.LOG_INFO, getBundleEventTypeName(eventType), null, null);
}
}

Back to the top