Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions trs/client/trs-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,31 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>

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.

why?

<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.10.0</version>
Comment thread
berezovskyi marked this conversation as resolved.
Outdated
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>5.11.0</version>
Comment thread
berezovskyi marked this conversation as resolved.
Outdated
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-junit-jupiter</artifactId>
<version>5.15.0</version>
<scope>test</scope>
</dependency>
<dependency>
Comment thread
berezovskyi marked this conversation as resolved.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public boolean fetchRemoteChangeLogs(ChangeLog currentChangeLog, List<ChangeLog>
private void pollAndProcessChanges() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
Date processingDateStart = new Date();
log.info("started dealing with TRS Provider: " + trsUriBase);
log.debug("started dealing with TRS Provider: " + trsUriBase);
Comment thread
berezovskyi marked this conversation as resolved.
Outdated

TrackedResourceSet updatedTrs = trsClient.extractRemoteTrs(trsUriBase);
boolean indexingStage = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,14 @@ public void update() {
} catch (Exception e) {
// FIXME Andrew@2019-07-15: can get stuck in the loop
log.warn("Force rebase");
log.debug("Force rebase exception: {}", e);
Comment thread
berezovskyi marked this conversation as resolved.
Outdated
lastProcessedChangeEventUri = null;
handler.rebase();
try {
handler.rebase();
} catch (Exception rebaseException) {
log.error("Error during rebase", rebaseException);
throw new RuntimeException("Failed to update TRS", e);
Comment thread
berezovskyi marked this conversation as resolved.
Outdated
}
}
}

Expand Down Expand Up @@ -116,7 +122,7 @@ private void processChangeEvent(ChangeEvent changeEvent) {
*/
private void pollAndProcessChanges() {

log.info("started dealing with TRS Provider: " + trsUriBase);
log.debug("started dealing with TRS Provider: " + trsUriBase);
Comment thread
berezovskyi marked this conversation as resolved.
Outdated

TrackedResourceSet updatedTrs = trsClient.extractRemoteTrs(trsUriBase);
boolean indexingStage = false;
Expand Down Expand Up @@ -272,11 +278,18 @@ private boolean fetchRemoteChangeLogs(ChangeLog currentChangeLog, List<ChangeLog
break;
}
previousChangeLog = currentChangeLog.getPrevious();
if (ProviderUtil.isNilUri(lastProcessedChangeEventUri) && ProviderUtil.isNilUri(previousChangeLog)) {
foundChangeEvent = true;
break;
}
Comment on lines +282 to +285

Copilot AI Jan 23, 2026

Copy link

Choose a reason for hiding this comment

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

The new nil-handling branch in fetchRemoteChangeLogs changes rollback/rebase behavior when both the stored cutoff and the changelog previous link are rdf:nil (or null via isNilUri). There doesn't appear to be a unit test covering this path for TrsProviderHandler (existing tests set cutoffEvent to a non-nil URI). Please add/extend a test that exercises the lastProcessedChangeEventUri == rdf:nil + currentChangeLog.previous == rdf:nil case to prevent regressions.

Copilot uses AI. Check for mistakes.

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.

we already do this for the concurrent provider in ConcurrentTrsProviderHandlerTest - we should unify the logic if possible

if (previousChangeLog == null) {
break;
}
currentChangeLog = trsClient.fetchRemoteChangeLog(previousChangeLog);
} else {
break;
}
} while (!RDF.nil.getURI().equals(previousChangeLog.toString()));
} while (previousChangeLog != null && !RDF.nil.getURI().equals(previousChangeLog.toString()));
Comment thread
berezovskyi marked this conversation as resolved.
Outdated
return foundChangeEvent;
}
Comment on lines 270 to 295

Copilot AI Jan 16, 2026

Copy link

Choose a reason for hiding this comment

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

This fix addresses an important scenario where a server starts with an empty base (cutoff event is null or RDF.nil) and adds change events without rebasing. However, there doesn't appear to be test coverage for this specific scenario. Consider adding a test case that verifies the behavior when lastProcessedChangeEventUri is set to RDF.nil (from an empty base) to ensure this fix works correctly and to prevent regression.

Copilot uses AI. Check for mistakes.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package org.eclipse.lyo.trs.client.handlers;

import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import org.apache.jena.sys.JenaSystem;
import org.apache.jena.vocabulary.RDF;
import org.eclipse.lyo.core.trs.ChangeLog;
import org.eclipse.lyo.trs.client.util.ITrackedResourceClient;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
public class ConcurrentTrsProviderHandlerTest {

@Mock
private ITrackedResourceClient trsClient;
@Mock
private IProviderEventHandler handler;

@BeforeAll
public static void initJena() {
JenaSystem.init();
}

@Test
public void testFetchRemoteChangeLogs_HitNil_Found() {
URI trsUri = URI.create("http://example.com/trs");
ConcurrentTrsProviderHandler provider = new ConcurrentTrsProviderHandler(trsUri, trsClient, handler);

try {
java.lang.reflect.Field field = ConcurrentTrsProviderHandler.class.getDeclaredField("lastProcessedChangeEventUri");
field.setAccessible(true);
field.set(provider, URI.create(RDF.nil.getURI()));
} catch (Exception e) {
Assertions.fail("Failed to set private field", e);
}

ChangeLog currentLog = new ChangeLog();
currentLog.setPrevious(URI.create(RDF.nil.getURI()));

List<ChangeLog> changeLogs = new ArrayList<>();
boolean found = provider.fetchRemoteChangeLogs(currentLog, changeLogs);

Assertions.assertTrue(found, "Should find sync event when hitting nil and last processed is nil");
Assertions.assertEquals(1, changeLogs.size());
}

@Test
public void testFetchRemoteChangeLogs_HitNil_NotFound() {
URI trsUri = URI.create("http://example.com/trs");
ConcurrentTrsProviderHandler provider = new ConcurrentTrsProviderHandler(trsUri, trsClient, handler);

try {
java.lang.reflect.Field field = ConcurrentTrsProviderHandler.class.getDeclaredField("lastProcessedChangeEventUri");
field.setAccessible(true);
field.set(provider, URI.create("http://example.com/event/1"));
} catch (Exception e) {
Assertions.fail("Failed to set private field", e);
}

ChangeLog currentLog = new ChangeLog();
currentLog.setPrevious(URI.create(RDF.nil.getURI()));

List<ChangeLog> changeLogs = new ArrayList<>();
boolean found = provider.fetchRemoteChangeLogs(currentLog, changeLogs);

Assertions.assertFalse(found, "Should NOT find sync event if we hit nil but were looking for specific event");
}
}
Loading