Skip to content

Commit

Permalink
feat: improved logging upon failure
Browse files Browse the repository at this point in the history
It's important users are able to debug their process properly if a test fails. To enable this we should provide them with proper logging upon a failure.
In the past we used the CompactRecordLogger from zeebe-test-util for this. This solution had 2 problems:
1. zeebe-test-util is not bound to Java 8. This means users running on Java 8 cannot use it.
2. The CompactRecordLogger provides too much information for the targeted users of this project.

To solve these problems I have introduced a new logger. This will also log all records of the stream, but only logs the most important fields that users need for debugging their processes. At the moment it is a guess which fields these are. Once we receive user feedback we can easily modify the logging for the specific records that are not clear enough.
  • Loading branch information
remcowesterhoud committed Feb 24, 2022
1 parent 81d49c8 commit 2cf0a25
Show file tree
Hide file tree
Showing 6 changed files with 307 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
import io.camunda.zeebe.util.sched.ActorSchedulingService;
import io.camunda.zeebe.util.sched.clock.ActorClock;
import io.camunda.zeebe.util.sched.clock.ControlledActorClock;
import io.grpc.BindableService;
import io.grpc.Server;
import io.grpc.ServerBuilder;
import java.util.Arrays;
import java.util.concurrent.CompletableFuture;

public class EngineFactory {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* in memory engine. To use this annotation Java 8 or higher is required. Docker also needs to be
* running.
*
* Annotating test classes with this annotation will do a couple of things:
* <p>Annotating test classes with this annotation will do a couple of things:
*
* <ul>
* <li>It start a docker container running and in memory engine.
Expand All @@ -24,8 +24,8 @@
* and increasing the time.
* <li>ZeebeClient - This is the client that allows you to communicate with the engine. It
* allows you to send commands to the engine.
* <li>RecordStream - This gives you access to all the records that are processed by
* the engine. It is what the assertions use to verify expectations. This grants you the
* <li>RecordStream - This gives you access to all the records that are processed by the
* engine. It is what the assertions use to verify expectations. This grants you the
* freedom to create your own assertions.
* </ul>
* <li>It will take care of cleaning up the engine and client when the testcase is finished.
Expand All @@ -37,6 +37,4 @@
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@ExtendWith(ZeebeProcessTestExtension.class)
public @interface ZeebeProcessTest {

}
public @interface ZeebeProcessTest {}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* This annotation can be used to test BPMN processes. It will run an in memory Zeebe engine. To use
* this annotation Java 17 or higher is required.
*
* Annotating test classes with this annotation will do a couple of things:
* <p>Annotating test classes with this annotation will do a couple of things:
*
* <ul>
* <li>It will create and start an in memory engine. This will be a new engine for each testcase.
Expand All @@ -23,8 +23,8 @@
* and increasing the time.
* <li>ZeebeClient - This is the client that allows you to communicate with the engine. It
* allows you to send commands to the engine.
* <li>RecordStream - This gives you access to all the records that are processed by
* the engine. It is what the assertions use to verify expectations. This grants you the
* <li>RecordStream - This gives you access to all the records that are processed by the
* engine. It is what the assertions use to verify expectations. This grants you the
* freedom to create your own assertions.
* </ul>
* <li>It will take care of cleaning up the engine and client when the testcase is finished.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.TestWatcher;
import org.junit.platform.commons.util.ReflectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ZeebeProcessTestExtension
implements BeforeEachCallback, AfterEachCallback, TestWatcher {

private static final Logger LOG = LoggerFactory.getLogger(ZeebeProcessTestExtension.class);
private static final String KEY_ZEEBE_CLIENT = "ZEEBE_CLIENT";
private static final String KEY_ZEEBE_ENGINE = "ZEEBE_ENGINE";

Expand Down Expand Up @@ -61,7 +64,7 @@ public void testFailed(final ExtensionContext extensionContext, final Throwable
final Object engineContent = getStore(extensionContext).get(KEY_ZEEBE_ENGINE);
final InMemoryEngine engine = (InMemoryEngine) engineContent;

System.out.println("===== Test failed! Printing records from the stream:");
LOG.error("===== Test failed! Printing records from the stream:");
RecordStream.of(engine.getRecordStreamSource()).print(true);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.camunda.zeebe.process.test.filters;

import io.camunda.zeebe.process.test.api.RecordStreamSource;
import io.camunda.zeebe.process.test.filters.logger.RecordStreamLogger;
import io.camunda.zeebe.protocol.record.Record;
import io.camunda.zeebe.protocol.record.RecordValue;
import io.camunda.zeebe.protocol.record.ValueType;
Expand All @@ -17,8 +18,6 @@
import io.camunda.zeebe.protocol.record.value.VariableDocumentRecordValue;
import io.camunda.zeebe.protocol.record.value.VariableRecordValue;
import io.camunda.zeebe.protocol.record.value.deployment.Process;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import org.slf4j.Logger;
Expand Down Expand Up @@ -105,24 +104,12 @@ public Iterable<Record<MessageSubscriptionRecordValue>> messageSubscriptionRecor
}

public void print(final boolean compact) {
final List<Record<?>> recordsList = new ArrayList<>();
recordStreamSource.records().forEach(recordsList::add);

if (compact) {
final StringBuilder stringBuilder = new StringBuilder();
recordsList.forEach(
record ->
stringBuilder
.append(record.getRecordType())
.append(" ")
.append(record.getValueType())
.append(" ")
.append(record.getIntent()));
LOG.info(stringBuilder.toString());
new RecordStreamLogger(recordStreamSource).log();
} else {
System.out.println("===== records (count: ${count()}) =====");
recordsList.forEach(record -> System.out.println(record.toJson()));
System.out.println("---------------------------");
LOG.info("===== records (count: ${count()}) =====");
recordStreamSource.records().forEach(record -> LOG.info(record.toJson()));
LOG.info("---------------------------");
}
}
}
Loading

0 comments on commit 2cf0a25

Please sign in to comment.