blob: f2f750f48742595afae716d33f67b7c86f46ac2a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
/*******************************************************************************
* Copyright (c) 2007, 2018 IBM Corporation All rights reserved. This program
* and the accompanying materials are made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution, and is
* available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.equinox.log.test;
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;
public TestListener() {
this(null);
}
public TestListener(Bundle testBundle) {
this.testBundle = testBundle == null ? OSGiTestsActivator.getContext().getBundle() : testBundle;
}
public synchronized void logged(LogEntry e) {
if (!testBundle.equals(e.getBundle()))
return; // discard logs from all other bundles
this.entry = e;
notifyAll();
}
public synchronized ExtendedLogEntry getEntryX() {
ExtendedLogEntry current = (ExtendedLogEntry) entry;
entry = null;
return current;
}
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.");
}
}
}
}
|