blob: dfd038b703f09db9fea1306320bc19b659981853 (
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
|
/*******************************************************************************
* Copyright (c) 2006, 2017 Cognos Incorporated, IBM Corporation and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0 which
* accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
******************************************************************************/
package org.eclipse.equinox.log.test;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;
import junit.framework.TestCase;
import org.osgi.service.log.LogEntry;
import org.osgi.service.log.LogListener;
public class TestListener2 extends TestCase implements LogListener {
private List<String> list;
private AtomicInteger flag = new AtomicInteger(0);
CountDownLatch latch;
public TestListener2(CountDownLatch countDownLatch) {
this.list = Collections.synchronizedList(new ArrayList());
this.latch = countDownLatch;
}
@Override
public void logged(LogEntry entry) {
//logged is never called in parallel. Added a check to see if two threads are accessing the logged method at the same time.
assertTrue(flag.compareAndSet(0, 1));
if (entry.getBundle().getSymbolicName().equals("org.eclipse.osgi")) {
list.add(entry.getMessage());
latch.countDown();
}
flag.set(0);
}
public List<String> getLogs() {
return this.list;
}
}
|