Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean the test logs #2606

Merged
merged 55 commits into from Feb 22, 2023
Merged

Clean the test logs #2606

merged 55 commits into from Feb 22, 2023

Conversation

smcvb
Copy link
Member

@smcvb smcvb commented Feb 15, 2023

This pull request aims to ensure a test run of the Axon Framework project does not flood you with logs.
To ensure this, numerous adjustments have been made:

  • Virtually all log4j2.properties files have been adjusted to be stricter on specific classes and sometimes packages, regarding what's logged and what's not during a test run. While touching these property files, properties logically belonging to one another have been grouped under a comment (e.g., command specific configuration is placed under # Commands).
  • Several classes directly invoked printf/println/etc methods to print out text used for test case validation. These are leftovers from when the test was built, so have been removed.
  • Some classes directly invoked logger methods to log the text used for test case validation. These are leftovers from when the test was built, so have been removed.
  • Tests using a database and thus a persistence.xml have been revamped to, in all cases, use a unique persistence unit name, reflecting the test or tests they're used in. Furthermore, mentions of addressbook in the hibernate.connection.url have been replaced for axontest.
  • Several classes, specifically those using Spring, had INFO, WARN, and ERROR logs from the framework automatically spinning up the Axon Server Connector. When applicable, Axon Server was disabled from these test. For those tests where Axon Server is necessary, a stub server with the bare bones to register a client are used. This server is based on the StubServer and PlatformService from the axonserver-connector module, although they're revamped to only allow the client registration.

Here are a couple of specific adjustments in this pull request worth mentioning:

  • The ContextInterceptor of the StubServer in the axonserver-connector module is now reused for both the Event and Command dummy platform service during testing. Doing so, we ensure the heartbeat monitoring log messages do not error out.
  • The EventProcessingModuleTest used mock StreamableMessageSources, which sometimes caused exceptions depending on the speed of the TEP or PSEP within the test. To completely eliminate this predicament, these tests now use a spied EmbeddedEventStore using the InMemoryEventStorageEngine.
  • The Hibernate 6 persistence.xml now does drop-and-create instead of create. This ensures we are not flooded with SQL execution exceptions because the tables already exist.
  • The Spring Boot 3 integration test module's pom is switched from logback to log4j configuration, by adjusting the dependencies accordingly.
  • I have adjusted several Spring Boot tests to use the ApplicationContextRunner. Doing so, these tests are aligned with the desired Spring Boot test format.
  • Saga test fixtures no use a no-op ListenerInvocationErrorHandler to ensure the LoggingErrorHandler does not kick in during tests.

Lastly, I resolved warnings and other issues whenever I touched test classes directly.

Adjust the log levels to:
 - WARN for the pooled directory
 - WARN for the MessageHandlerRegistrar
 - ERROR for the DefaultConfigurer

#enhancement/shorten-build-logs
Whether a TEP or PSEP is fast enough to invoke the openStream method is
not fixed. Hence, sometimes the tests receive a NullPointerException and
 sometimes they do not. We should make the sources global fields and
 return a mocked BlockingStream.

#enhancement/shorten-build-logs
Set XStreamSerializer to ensure a safe variant is used.

#enhancement/shorten-build-logs
Resolve warnings

#enhancement/shorten-build-logs
Set LoggingCallback log level to ERROR

#enhancement/shorten-build-logs
The test usesDuplicateCommandHandlerResolver() validating duplicate
handler resolution is taken care off, causes the message to log for all
other test cases. Hence, the global bus can be configured to not log
at all.

#enhancement/shorten-build-logs
Ensure test does not throw exception into the logs. To that end, we
should not interrupt, and adjust the gateway to expect a
TimeoutException. While touching the file, resolve warnings.

#enhancement/shorten-build-logs
Clear test classes of warnings and indentation inconsistencies

#enhancement/shorten-build-logs
Expand on logger configuration to not pollute test and build logs

#enhancement/shorten-build-logs
Align logger configurations, to follow the paradigm of axon-messaging

#enhancement/shorten-build-logs
- Rename 'em' to 'entityManager' for clarity
- Make the EntityManagerFactory a field, to be able to close it after a
test
- Adjust the persistence unit name to be very specific for this test
- Move the properties to the persistence.xml

#enhancement/shorten-build-logs
Replace the mock StreamableMessageSource and BlockingStream, for an
actual EventStore using the in-memory EventStorageEngine. For whatever
reason, the current version of Mockito caused this approach to fail with
 OutOfMemory errors during a Maven test run, and only during a Maven
 test run. As the fact it is a mock or an EmbeddedEventStore instance
 makes no difference for test, we should switch this.

#enhancement/shorten-build-logs
Fine tune logging configuration by setting the GlobalMetricRegistry log
level to WARN

#enhancement/shorten-build-logs
Add properties to disable AxonServer and the SpringBoot banner

#enhancement/shorten-build-logs
Add log4j2.properties to fine tune test logging

#enhancement/shorten-build-logs
Fine tune logging configuration by:
- Adding the LoggingCallback on ERROR level
- Adding the AbstractEventStore on ERROR level
- Adding the AbstractSnapshotter on ERROR level
- Adding the Test Container specifics on ERROR level

#enhancement/shorten-build-logs
Fine tune logging configuration by:
- Adding the AbstractEventStore on ERROR level
- Adding the SimpleQueryUpdateEmitter on OFF level
- Adding the SimpleDeadlineManager on OFF level
- Adding the axonserver-connector-java on WARN level
- Adding the JobRunr on WARN level
- Adding the Test Container on WARN and OFF level
- Adjust the TrackingEventProcessor from ERROR to OFF

#enhancement/shorten-build-logs
Clarify log line to be part of the test case. While touching the file,
resolve some warnings

#enhancement/shorten-build-logs
Ignore the onErrorDropped default logging hook, as it does not benefit
this test case. Be sure to revert this setting after the test runs.

#enhancement/shorten-build-logs
- QueryEventHandlingTest.java is not clear enough. Rename this class to
ProjectorTest
- Disable auto-configurer module loading, since that will disable the
automatic connection of Axon Server and thus clean the logs

#enhancement/shorten-build-logs
Set a no-op ListenerInvocationErrorHandler i.o. the LoggingErrorHandler
to minimize the amount of logs

#enhancement/shorten-build-logs
Fine tune logging configuration by:
- Adding the LoggingDuplicateCommandHandlerResolver on ERROR level
- Adding the Test Container specifics on the levels ERROR and OFF

#enhancement/shorten-build-logs
Remove the logger, as it was only used during test case construction.

#enhancement/shorten-build-logs
Fine tune logging configuration by:
- Adding the ChainingConverter on OFF level
- Adding the AbstractSnapshotter on ERROR level
- Adding the SpringAxonAutoConfigurer on ERROR level
- Adding the SpringBeanParameterResolverFactory on ERROR level
- Adding mchange-v2 name space on WARN level
- Add Test Container specific levels to ERROR and OFF

#enhancement/shorten-build-logs
- Replace addressbook for axontext in the JDBC URL
- Rename the persistence unit to AxonSpringTest
- Set the persistence unit provider to HibernatePersistenceProvider
- Set the name of the MyAggregate entity to "myAggregate" as otherwise a
 dollar sign is used to reference the parent and inner class
 combination. Hibernate doesn't like that.

#enhancement/shorten-build-logs
- Move PlatformService to the utils packages. This is more inline with
the desired package structuring.
- Extract the ContextInterceptor from the StubServer and place under
utils. This is pre-work to reuse the interceptor.
- Use the ContextInterceptor in the DummyMessagePlatformServer. This
ensures we no longer receive NPE on health monitoring messages

#enhancement/shorten-build-logs
Fine tune logging configuration by:
- Adding the AbstractEventStore on ERROR level
- Adding the AbstractAxonServerChannel on WARN level
- Adding the AxonServerConnectionFactory on ERROR level
- Adding the ControlChannelImpl on WARN level
- Adding the CommandChannelImpl on WARN level
- Adding the HeartbeatMonitor on WARN level
- Adding the AxonServerManagedChannel on ERROR level
- Adding the QueryChannelImpl on WARN level
- Add Test Container specific levels to ERROR and OFF

#enhancement/shorten-build-logs
Disable Axon Server when it is not needed for the tests, as this will
minimize the logs greatly

#enhancement/shorten-build-logs
Fine tune logging configuration by:
- Adding the pooled package on WARN level
- Adding the AxonServerConnectionManager on ERROR level
- Adding the AxonServerConnectionFactory on ERROR level
- Adding the ControlChannelImpl on WARN level
- Adding the HeartbeatMonitor on WARN level
- Adding the AxonServerManagedChannel on WARN level
- Adding org.axonframework.springboot.autoconfig on WARN level
- Adding org.axonframework.springboot.util on ERROR level
- Adding the SagaCustomizeIntegrationTest on WARN level
- Adding the AnnotationMBeanExporter on WARN level
- Adding the AnnotationConfigApplicationContext on ERROR level

#enhancement/shorten-build-logs
Remove logger used for test validation

#enhancement/shorten-build-logs
Several of the tests require the existence of a connection to what they
expect to be Axon Server. Although we can set up a test container for
this, doing so will lengthen the tests quite some. Especially since the
only required operation to work, is registering a client. Hence, we can
copy the stub solutions present in the axonserver-connector module, and
fine tune them for these tests. To not get clashes in port numbers
between closing server instances, the TcpUtils is also reused, setting a
system property for the entire test class (and clearing it afterwards).
While add it, adjust some of the tests to use the
ApplicationContextRunner approach, streamlining the test cases.

#enhancement/shorten-build-logs
Fine tune logging configuration by:
- Adding the DefaultCommandGateway on ERROR level
- Adding the AbstractEventStore on ERROR level
- Adding the pooled package on WARN level
- Adding the DeadLetteredEventProcessingTask on ERROR level
- Adding the org.axonframework.messaging.deadletter on WARN level
- Adding the org.axonframework.eventhandling.deadletter on WARN level
- Adding AxonServerConnectionManager on ERROR level
- Adding AxonServerConnectionFactory on WARN level
- Adding ControlChannelImpl on WARN level
- Adding HeartbeatMonitor on WARN level
- Adding AxonServerManagedChannel on WARN level
- Adding org.axonframework.springboot.autoconfig on WARN level
- Adding org.axonframework.springboot.util on ERROR level
- Adding the SagaCustomizeIntegrationTest on WARN level
- Adding the SagaCustomizeIntegrationTest on WARN level
- Adding the TrackingEventProcessorIntegrationTest on WARN level
- Adding the com.zaxxer.hikari package on WARN level
- Adding the "SQL dialect" on WARN level
- Adding the org.springframework.data package on WARN level
- Add Test Container specific levels to ERROR and OFF

#enhancement/shorten-build-logs
Fine tune logging configuration by adding the AnnotationMBeanExporter on
 WARN level

#enhancement/shorten-build-logs
Fine tune logging configuration by adding the JdbcSagaStore on ERROR
level

#enhancement/shorten-build-logs
Fine tune logging configuration by adding the DeepEqualsMatcher on ERROR
 level

#enhancement/shorten-build-logs
Remove stack trace printing

#enhancement/shorten-build-logs
@smcvb smcvb added Type: Enhancement Use to signal an issue enhances an already existing feature of the project. Priority 3: Could Low priority. Issues that are nice to have but have a straightforward workaround. Status: In Progress Use to signal this issue is actively worked on. labels Feb 15, 2023
@smcvb smcvb added this to the Release 4.8.0 milestone Feb 15, 2023
@smcvb smcvb self-assigned this Feb 15, 2023
Fix all jdbc urls to axontest i.o. addressbook

#2606
Move test specific log settings to the bottom

#2606
Better specify log configuration for AF SpringBoot

#2606
Rename persistence unit to something test specific

#2606
Remove disabled annotation from tests

#2606
Drop usage of old Sping xml config. The axon-messaging/db-context.xml
still anticipated a persistence unit name of "eventStore". Although we
can fix the xml I think it's smarter to move to the annotation based
configuration.

#2606
Switch JDBC URL to point to axontest i.o. address-book

#2606
Switch persistence unit name to "AxonSpringTest" i.o. ""eventStore"

#2606
Switch persistence unit name to "integrationtest" i.o. ""eventStore"

#2606
@sonarcloud
Copy link

sonarcloud bot commented Feb 21, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Copy link
Contributor

@gklijs gklijs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, might even have made the build a bit faster.

@smcvb smcvb merged commit f526be0 into master Feb 22, 2023
@smcvb smcvb deleted the enhancement/shorten-build-logs branch February 22, 2023 08:11
@smcvb smcvb added Status: Resolved Use to signal that work on this issue is done. and removed Status: In Progress Use to signal this issue is actively worked on. labels Feb 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority 3: Could Low priority. Issues that are nice to have but have a straightforward workaround. Status: Resolved Use to signal that work on this issue is done. Type: Enhancement Use to signal an issue enhances an already existing feature of the project.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants