Skip to content

BITMAG-1247-date-time-modernizing#82

Open
Knud-Aage wants to merge 231 commits intomasterfrom
BITMAG-1247-date-time-modernizing
Open

BITMAG-1247-date-time-modernizing#82
Knud-Aage wants to merge 231 commits intomasterfrom
BITMAG-1247-date-time-modernizing

Conversation

@Knud-Aage
Copy link
Copy Markdown
Contributor

This PR addresses the long-standing technical debt of using legacy Java date/time classes.

The legacy date/time API is confusing, error-prone, mutable, and not thread-safe. It has been replaced by modern, immutable, thread-safe, and highly explicit API

Removal of XMLGregorianCalendar, though, awaits clarification, but will be done as soon as possible

- Added JUnit 5 annotations to BitrepositoryTestSuite
- Added GlobalSuiteExtension to implement JUnit 5 extension points for suite-level setup and teardown.
- Ensured consistency and correctness of test suite configuration and setup methods.

This commit updates the test suite configuration to use JUnit 5 annotations, allowing for more flexible and powerful test suite management.
…junit' into BITMAG-1244-junit-bitrepository-core

# Conflicts:
#	bitrepository-core/src/test/java/org/bitrepository/protocol/IntegrationTest.java
#	bitrepository-core/src/test/java/org/bitrepository/protocol/bus/ActiveMQMessageBusTest.java
#	bitrepository-core/src/test/java/org/bitrepository/protocol/performancetest/MessageBusNumberOfListenersStressTest.java
…n install can't run because it gives errors in the module bitrepository-client, which hasn't been converted to junit 5 yet.
…use the codebase is now using junit since there was a security vulnerability with TestNG
…accept

# Conflicts:
#	bitrepository-core/src/test/java/org/bitrepository/protocol/IntegrationTest.java
…gured. The task is almost done but not there yet.

To emulate jaccept a try to report during test as jaccept does, but that task is also not done yet.
…get/allure-results folder which are used to create the final report that are shown to the user. That report is created by using mvn allure:serve
…source folder were removed.

Made minor corrections, so now all tests succeed. There are a few tests that were disabled.
…ls to use String.format instead of StringBuilder
…g' into BITMAG-1247-date-time-modernizing

# Conflicts:
#	bitrepository-client/src/test/java/org/bitrepository/client/TestEventHandler.java
#	bitrepository-client/src/test/java/org/bitrepository/modify/deletefile/DeleteFileClientComponentTest.java
#	bitrepository-client/src/test/java/org/bitrepository/modify/deletefile/DeleteFileClientTestWrapper.java
#	bitrepository-core/src/main/java/org/bitrepository/common/utils/CalendarUtils.java
#	bitrepository-core/src/test/java/org/bitrepository/common/utils/FileUtilsTest.java
#	bitrepository-core/src/test/java/org/bitrepository/protocol/bus/ActiveMQMessageBusTest.java
#	bitrepository-core/src/test/java/org/bitrepository/protocol/bus/MessageReceiver.java
#	bitrepository-core/src/test/java/org/bitrepository/protocol/fileexchange/LocalFileExchangeTest.java
#	bitrepository-core/src/test/java/org/bitrepository/protocol/performancetest/MessageBusTimeToSendMessagesStressTest.java
#	bitrepository-integrity-service/src/test/java/org/bitrepository/integrityservice/component/IntegrityServiceComponentTest.java
#	bitrepository-reference-pillar/src/test/java/org/bitrepository/pillar/integration/PillarIntegrationTest.java
#	bitrepository-reference-pillar/src/test/java/org/bitrepository/pillar/integration/func/deletefile/DeleteFileRequestIT.java
#	bitrepository-reference-pillar/src/test/java/org/bitrepository/pillar/integration/func/getfile/GetFileRequestIT.java
#	bitrepository-reference-pillar/src/test/java/org/bitrepository/pillar/integration/func/putfile/IdentifyPillarsForPutFileIT.java
#	bitrepository-reference-pillar/src/test/java/org/bitrepository/pillar/integration/model/PillarFileManager.java
#	bitrepository-reference-pillar/src/test/resources/logback-test.xml
#	bitrepository-service/src/test/java/org/bitrepository/service/audit/AuditTrailContributorDatabaseMigrationTest.java
@ole-v-v
Copy link
Copy Markdown
Contributor

ole-v-v commented Mar 31, 2026

Did you somehow forget the use of Date in the AuditTrailCollector and LocalAuditTrailPreserver classes? Also the RestIntegrityService class and classes under bitrepository-reference-pillar/src/test/java/org/bitrepository/pillar/messagefactories seem not to be fully converted yet.

Also some timer task code uses old methods. Since we already have an issue to rewrite our timer tasks, I suggest you can let it be for now.

Copy link
Copy Markdown
Contributor

@ole-v-v ole-v-v left a comment

Choose a reason for hiding this comment

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

A strong pull request demonstrating a good command of java.time. We will be very happy about this change.

For naming new methods, when you add Instant to some previous method name. consider deleting Date or Time from the name to evade redundancy and the name becoming overly long.

Comment on lines +55 to +56
private TimeZone localTimeZone = TimeZone.getDefault();
private ZoneId localZoneId = ZoneId.systemDefault();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Having both of a TimeZone and a ZoneId is redundant. I’d prefer just the modern ZoneId (with conversions as necessary). Granted, you are meticulously making sure that the two always refer to the same time zone, so the code works correctly also with the redundancy.

* @return The startDate;
*/
public Date getStartDate() {
public Instant getStartDateInstant() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We could also just name it getStartInstant()? Or even just getStart()?? I believe an alarm starts at a point in time, so I don’t think the word “date” adds anything helpful here? Similarly for getEnd[Date]Instant().

Optional, if we want to take it a step further, we may rename constructor and method parameters and even instance variables to just start and end (leaving Date out from the names), or similar.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed the name to start and end

@@ -44,12 +45,12 @@ public class AlarmDatabaseExtractionModel {
/**
* @see #getStartDate().
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I suggest referring to the new getStartDateInstant() instead. Similarly for end instant below.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done


/**
* @param startDate The startDate.
* @see #getStartDate()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I suggest referring to the new getStartDateInstant() instead. Similarly for end instant below.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines +65 to +71
* @param componentID [OPTIONAL] The id of the component.
* @param alarmCode [OPTIONAL] The alarm code.
* @param minDate [OPTIONAL] The earliest date for the alarms.
* @param maxDate [OPTIONAL] The latest date for the alarms.
* @param fileID [OPTIONAL] The id of the file, which the alarms are connected.
* @param collectionID the ID of the collection. Perhaps it is optional
* @param count [OPTIONAL] The maximum number of alarms to retrieve from the store.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You’ve got quite impressive Javadoc comments on methods that you have deprecated.

While the caller needs to know which parameters are allowed to be null, for my part I’m not fond of using all caps (except in abbreviations, when referring to constants declared in shouting case and similar). I would probably use wording along “The ID of the component or null for all components” (if this is the intended meaning; if you don’t know, then just “or null”).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed (OPTIONAL) and added with null

public Instant getNextRunInstant(JobID jobId) {
if (intervalTasks.containsKey(jobId)) {
return intervalTasks.get(jobId).getNextRunInstant();
} else return null;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

May use this occasion to put return statement on its own line enclosed in curly braces. Or depending on taste leave out else and just put the return statement on its own line.

Comment on lines +134 to +135
if (nextRun != null && (getNextRunInstant() == null ||
getNextRunInstant().toEpochMilli() <= System.currentTimeMillis())) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would prefer:

        if (nextRun != null && 
                (getNextRunInstant() == null || ! getNextRunInstant().isAfter(Instant.now()))) {

Breaking the line at a higher level of the Boolean expression and using “not after” to mean “before or equal to” (may also spell it out).

}

/**
* @return The duration of the workflow if it has been started, else 0.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

May use this occasion for adding to the documentation that the duration is in milliseconds. Or even provide a method that returns a Duration object.

return System.currentTimeMillis() - start.toEpochMilli();
} else {
return finish.getTime() - start.getTime();
return finish.toEpochMilli() - start.toEpochMilli();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

My suggestion:

            return ChronoUnit.MILLIS.between(start, finish);

Comment on lines +201 to +202
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSXXX", Locale.ROOT);
Instant summertimeTS = ZonedDateTime.parse("2015-10-25T02:59:54.000+02:00", formatter).toInstant();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Leave out the formatter and just do

        Instant summertimeTS = OffsetDateTime.parse("2015-10-25T02:59:54.000+02:00").toInstant();

Same for the standard time case below. (This is testing java.time, which we should not want to consider our job; let it be.)

Comment on lines +224 to +245
// @Tag("regressiontest")
// public void onePillarRespondingWithPartialPutAllowed() throws Exception {
// addReference("<a href=https://sbforge.org/jira/browse/BITMAG-598>" +
// "BITMAG-598 It should be possible to putFiles, even though only a subset of the pillars are available</a>");
// addDescription("Tests the handling of missing identification responses from one pillar, " +
// "when partial put are allowed");
// addFixture("Sets the identification timeout to 100 ms and allow partial puts.");
//
// settingsForCUT.getRepositorySettings().getClientSettings()
// .setIdentificationTimeoutDuration(datatypeFactory.newDuration(100));
// settingsForCUT.getReferenceSettings().getPutFileSettings().setPartialPutsAllow(true);
// TestEventHandler testEventHandler = new TestEventHandler();
// PutFileClient putClient = createPutFileClient();
//
// addStep("Request the putting of a file through the PutClient",
// "A identification request should be dispatched.");
// putClient.putFile(collectionID, httpServerConfiguration.getURL(DEFAULT_FILE_ID), DEFAULT_FILE_ID, 0, null,
// null, testEventHandler, null);
// Assertions.assertEquals(OperationEventType.IDENTIFY_REQUEST_SENT, testEventHandler.waitForEvent().getEventType());
// IdentifyPillarsForPutFileRequest receivedIdentifyRequestMessage =
// collectionReceiver.waitForMessage(IdentifyPillarsForPutFileRequest.class);
//
Copy link
Copy Markdown
Contributor

@ole-v-v ole-v-v Apr 10, 2026

Choose a reason for hiding this comment

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

Right. Allow me to suggest you stick in a comment saying approximately what the above reply says. And then move on.

@bitrepository bitrepository deleted a comment from ole-v-v Apr 10, 2026
Copy link
Copy Markdown
Contributor

@ole-v-v ole-v-v left a comment

Choose a reason for hiding this comment

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

A strong pull request demonstrating a good command of java.time. We will be very happy about this change.

For naming new methods, when you add Instant to some previous method name. consider deleting Date or Time from the name to evade redundancy and the name becoming overly long.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants