aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2018-04-09 11:00:18 -0400
committerThomas Watson2018-04-09 11:00:18 -0400
commit55b58a7acb2d6b448c56e9e74694c84d0ea4aa0a (patch)
treec7e691f2f027e618428a6c7bb197b2042cb40b54
parentd40e89ffa170de5e7337bc91c7fcad66fac14d43 (diff)
downloadrt.equinox.framework-55b58a7acb2d6b448c56e9e74694c84d0ea4aa0a.tar.gz
rt.equinox.framework-55b58a7acb2d6b448c56e9e74694c84d0ea4aa0a.tar.xz
rt.equinox.framework-55b58a7acb2d6b448c56e9e74694c84d0ea4aa0a.zip
service reference Change-Id: Ieacda0ecbb60502002dbd0ca2cb64ad0db6b81bf Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/LogServiceTest.java48
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/LogServiceManager.java2
2 files changed, 48 insertions, 2 deletions
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 5c16a48d7..12d87736b 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
@@ -8,15 +8,24 @@
*******************************************************************************/
package org.eclipse.equinox.log.test;
+import java.util.Collections;
import java.util.HashMap;
+import java.util.Hashtable;
import java.util.Map;
import junit.framework.TestCase;
import org.eclipse.osgi.tests.OSGiTestsActivator;
+import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
-import org.osgi.service.log.*;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.log.LogEntry;
+import org.osgi.service.log.LogLevel;
+import org.osgi.service.log.LogReaderService;
+import org.osgi.service.log.LogService;
+import org.osgi.service.log.Logger;
import org.osgi.service.log.admin.LoggerAdmin;
import org.osgi.service.log.admin.LoggerContext;
+@SuppressWarnings("deprecation")
public class LogServiceTest extends TestCase {
private LogService log;
@@ -267,4 +276,41 @@ public class LogServiceTest extends TestCase {
assertTrue(entry.getException().getMessage().equals(t.getMessage()));
assertTrue(entry.getServiceReference() == logReference);
}
+
+ public void testServiceEventLog() throws InterruptedException {
+ 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());
+ assertEquals("Wrong bundle.", context.getBundle(), entry.getBundle());
+ assertNull("Wrong exception.", entry.getException());
+ assertEquals("Wrong service reference.", ref, entry.getServiceReference());
+ assertEquals("Wrong message.", "ServiceEvent REGISTERED", entry.getMessage());
+
+ 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());
+ assertEquals("Wrong bundle.", context.getBundle(), entry.getBundle());
+ assertNull("Wrong exception.", entry.getException());
+ assertEquals("Wrong service reference.", ref, entry.getServiceReference());
+ 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());
+ assertEquals("Wrong bundle.", context.getBundle(), entry.getBundle());
+ assertNull("Wrong exception.", entry.getException());
+ assertEquals("Wrong service reference.", ref, entry.getServiceReference());
+ assertEquals("Wrong message.", "ServiceEvent UNREGISTERING", entry.getMessage());
+ }
}
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 c9b7579af..4d877d257 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
@@ -143,7 +143,7 @@ public class LogServiceManager implements BundleListener, FrameworkListener, Ser
int logType = (eventType == ServiceEvent.MODIFIED) ? LogService.LOG_DEBUG : LogService.LOG_INFO;
if (logReaderServiceFactory.isLoggable(bundle, LOGGER_SERVICE_EVENT, logType)) {
LoggerImpl logger = (LoggerImpl) systemBundleLog.getLogger(LOGGER_SERVICE_EVENT);
- logger.log(bundle, null, null, logType, getServiceEventTypeName(eventType), null);
+ logger.log(bundle, reference, null, logType, getServiceEventTypeName(eventType), null);
}
}