@Test public void logContextsAcrossThreads_shouldCarryDiagnosticContextAcrossThreads() throws Exception { String jobId = theClass.logContextsAcrossThreads(); OpsLogger<CollectorLogMessages> nestedLogger = mockLogger.with(new ClassThatLogs.LocalContext(jobId)); verify(nestedLogger).log(CollectorLogMessages.SUCCESS, 1); verify(nestedLogger).log(CollectorLogMessages.SUCCESS, 2); verify(nestedLogger).log(CollectorLogMessages.SUCCESS, 3); verify(nestedLogger).log(CollectorLogMessages.SUCCESS, 4); verify(nestedLogger).log(CollectorLogMessages.SUCCESS, 5); verifyNoMoreInteractions(nestedLogger); nestedLogger = mockLogger.with(new ClassThatLogs.LocalContext("fred")); verify(nestedLogger).log(CollectorLogMessages.SUCCESS, 6); verify(nestedLogger).log(CollectorLogMessages.SUCCESS, 7); verify(nestedLogger).log(CollectorLogMessages.SUCCESS, 8); verify(nestedLogger).log(CollectorLogMessages.SUCCESS, 9); verify(nestedLogger).log(CollectorLogMessages.SUCCESS, 10); verifyNoMoreInteractions(nestedLogger); }
public String logContextsAcrossThreads() { LocalContext context = new LocalContext(UUID.randomUUID().toString()); IntStream.rangeClosed(1, 5).parallel().forEach(i -> logger.with(context).log(SUCCESS, i)); IntStream.rangeClosed(6, 10).parallel().forEach(i -> logger.with(new LocalContext("fred")).log(SUCCESS, i)); return context.getJobId(); }
ClassThatLogs { public String logContextsAcrossThreads() { LocalContext context = new LocalContext(UUID.randomUUID().toString()); IntStream.rangeClosed(1, 5).parallel().forEach(i -> logger.with(context).log(SUCCESS, i)); IntStream.rangeClosed(6, 10).parallel().forEach(i -> logger.with(new LocalContext("fred")).log(SUCCESS, i)); return context.getJobId(); } }
ClassThatLogs { public String logContextsAcrossThreads() { LocalContext context = new LocalContext(UUID.randomUUID().toString()); IntStream.rangeClosed(1, 5).parallel().forEach(i -> logger.with(context).log(SUCCESS, i)); IntStream.rangeClosed(6, 10).parallel().forEach(i -> logger.with(new LocalContext("fred")).log(SUCCESS, i)); return context.getJobId(); } ClassThatLogs(OpsLogger<CollectorLogMessages> logger); }
ClassThatLogs { public String logContextsAcrossThreads() { LocalContext context = new LocalContext(UUID.randomUUID().toString()); IntStream.rangeClosed(1, 5).parallel().forEach(i -> logger.with(context).log(SUCCESS, i)); IntStream.rangeClosed(6, 10).parallel().forEach(i -> logger.with(new LocalContext("fred")).log(SUCCESS, i)); return context.getJobId(); } ClassThatLogs(OpsLogger<CollectorLogMessages> logger); void foo(); void bar(); String logContextsAcrossThreads(); void baz(); }
ClassThatLogs { public String logContextsAcrossThreads() { LocalContext context = new LocalContext(UUID.randomUUID().toString()); IntStream.rangeClosed(1, 5).parallel().forEach(i -> logger.with(context).log(SUCCESS, i)); IntStream.rangeClosed(6, 10).parallel().forEach(i -> logger.with(new LocalContext("fred")).log(SUCCESS, i)); return context.getJobId(); } ClassThatLogs(OpsLogger<CollectorLogMessages> logger); void foo(); void bar(); String logContextsAcrossThreads(); void baz();  }