-
Notifications
You must be signed in to change notification settings - Fork 20
fix(trs): consume RefImpl and Jazz TRS feeds #873
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
base: master
Are you sure you want to change the base?
Changes from 4 commits
fc1f918
53d3489
cb0e2c0
9431edf
ccb92f4
7dc9594
5e28993
7482c9b
1cc4b84
974ad92
cdb5aef
d566397
e8517ca
46f9426
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -127,9 +127,27 @@ | |
| <dependency> | ||
| <groupId>junit</groupId> | ||
| <artifactId>junit</artifactId> | ||
| <version>4.13.2</version> | ||
| <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> | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be dep-managed |
||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
|
berezovskyi marked this conversation as resolved.
|
||
|
|
||
| <groupId>org.slf4j</groupId> | ||
| <artifactId>slf4j-simple</artifactId> | ||
| <scope>test</scope> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -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; | ||
|
|
@@ -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
|
||
| if (previousChangeLog == null) { | ||
| break; | ||
| } | ||
| currentChangeLog = trsClient.fetchRemoteChangeLog(previousChangeLog); | ||
| } else { | ||
| break; | ||
|
|
||
| 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"); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?