Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
18 changes: 18 additions & 0 deletions trs/client/trs-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,27 @@
<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>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>5.21.0</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.

should be dep-managed

<scope>test</scope>
</dependency>
<dependency>
Comment thread
berezovskyi marked this conversation as resolved.

<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
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);

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,15 @@ 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);
lastProcessedChangeEventUri = null;
handler.rebase();
try {
handler.rebase();
} catch (Exception rebaseException) {
log.error("Error during rebase", rebaseException);
rebaseException.addSuppressed(e);
throw new RuntimeException("Failed to update TRS", rebaseException);
}
}
}

Expand Down Expand Up @@ -116,7 +123,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);

TrackedResourceSet updatedTrs = trsClient.extractRemoteTrs(trsUriBase);
boolean indexingStage = false;
Expand Down Expand Up @@ -272,6 +279,13 @@ 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;
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