|
3 | 3 | import org.fluentd.logger.sender.Event;
|
4 | 4 | import org.fluentd.logger.sender.NullSender;
|
5 | 5 | import org.fluentd.logger.util.MockFluentd;
|
6 |
| -import org.junit.Ignore; |
7 | 6 | import org.junit.Test;
|
8 | 7 | import org.msgpack.MessagePack;
|
9 | 8 | import org.msgpack.unpacker.Unpacker;
|
|
20 | 19 | import java.util.concurrent.TimeUnit;
|
21 | 20 |
|
22 | 21 | import static org.junit.Assert.assertEquals;
|
| 22 | +import static org.junit.Assert.assertFalse; |
| 23 | +import static org.junit.Assert.assertTrue; |
23 | 24 |
|
24 | 25 | public class TestFluentLogger {
|
25 | 26 | private Logger _logger = LoggerFactory.getLogger(TestFluentLogger.class);
|
@@ -227,26 +228,29 @@ public void process(MessagePack msgpack, Socket socket) throws IOException {
|
227 | 228 |
|
228 | 229 | // start loggers
|
229 | 230 | FluentLogger logger = FluentLogger.getLogger("testtag", host, port);
|
| 231 | + assertFalse(logger.isConnected()); |
230 | 232 | {
|
231 | 233 | Map<String, Object> data = new HashMap<String, Object>();
|
232 | 234 | data.put("k1", "v1");
|
233 | 235 | data.put("k2", "v2");
|
234 | 236 | logger.log("test01", data);
|
235 | 237 | }
|
| 238 | + assertTrue(logger.isConnected()); |
236 | 239 |
|
237 | 240 | TimeUnit.MILLISECONDS.sleep(500);
|
238 | 241 | _logger.info("Closing the current fluentd instance");
|
239 | 242 | fluentd1.closeClientSockets();
|
240 | 243 | fluentd1.close();
|
241 | 244 |
|
242 | 245 | TimeUnit.MILLISECONDS.sleep(500);
|
243 |
| - |
| 246 | + assertTrue(logger.isConnected()); |
244 | 247 | {
|
245 | 248 | Map<String, Object> data = new HashMap<String, Object>();
|
246 | 249 | data.put("k3", "v3");
|
247 | 250 | data.put("k4", "v4");
|
248 | 251 | logger.log("test01", data);
|
249 | 252 | }
|
| 253 | + assertFalse(logger.isConnected()); |
250 | 254 |
|
251 | 255 | final List<Event> elist2 = new ArrayList<Event>();
|
252 | 256 | MockFluentd fluentd2 = new MockFluentd(port, new MockFluentd.MockProcess() {
|
@@ -274,19 +278,18 @@ public void process(MessagePack msgpack, Socket socket) throws IOException {
|
274 | 278 | data.put("k6", "v6");
|
275 | 279 | logger.log("test01", data);
|
276 | 280 | }
|
| 281 | + assertTrue(logger.isConnected()); |
277 | 282 |
|
278 | 283 | // close loggers
|
279 | 284 | FluentLogger.closeAll();
|
280 | 285 | Thread.sleep(2000);
|
281 | 286 |
|
282 | 287 | fluentd2.close();
|
283 | 288 |
|
284 |
| - |
285 | 289 | // wait for unpacking event data on fluentd
|
286 | 290 | TimeUnit.MILLISECONDS.sleep(2000);
|
287 | 291 | threadManager.join();
|
288 | 292 |
|
289 |
| - |
290 | 293 | // check data
|
291 | 294 | assertEquals(1, elist1.size());
|
292 | 295 | assertEquals("testtag.test01", elist1.get(0).tag);
|
@@ -361,6 +364,14 @@ public void process(MessagePack msgpack, Socket socket) throws IOException {
|
361 | 364 |
|
362 | 365 | final FluentLogger logger = FluentLogger.getLogger(null, host, port);
|
363 | 366 | ExecutorService executorService = Executors.newFixedThreadPool(N);
|
| 367 | + /* |
| 368 | + * Each thread emits the following events LOOP times |
| 369 | + * Thread#0: {'0' => 0} |
| 370 | + * Thread#1: {'0' => 0, '1' => 1} |
| 371 | + * Thread#2: {'0' => 0, '1' => 1, '2' => 2} |
| 372 | + * : |
| 373 | + * Thread#(N-1): {'0' => 0, '1' => 1, '2' => 2 ... '(N-1)' => (N-1)} |
| 374 | + */ |
364 | 375 | for (int i = 0; i < N; i++) {
|
365 | 376 | final int ii = i;
|
366 | 377 | executorService.execute(new Runnable() {
|
|
0 commit comments