Skip to content

Commit

Permalink
[MRESOLVER-352] - Duplicate METADATA_DOWNLOADING event is being sent (s…
Browse files Browse the repository at this point in the history
…4u#280)

Ensure that METADATA_DOWNLOADING event is sent only once in case the lock "upgrade" happens.

--

https://issues.apache.org/jira/browse/MRESOLVER-352
  • Loading branch information
c00ler authored Apr 21, 2023
1 parent 2a9351d commit 7d17bc3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,6 @@ private List<MetadataResult> resolve(
.getPathForRemoteMetadata(
metadata, request.getRepository(), request.getRequestContext()));

metadataDownloading(
session,
trace,
result.getRequest().getMetadata(),
result.getRequest().getRepository());

ResolveTask task = new ResolveTask(
session, trace, result, installFile, checks, policy.getChecksumPolicy());
tasks.add(task);
Expand Down Expand Up @@ -351,6 +345,9 @@ private List<MetadataResult> resolve(
RunnableErrorForwarder errorForwarder = new RunnableErrorForwarder();

for (ResolveTask task : tasks) {
metadataDownloading(
task.session, task.trace, task.request.getMetadata(), task.request.getRepository());

executor.execute(errorForwarder.wrap(task));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import java.util.Set;

import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositoryEvent;
import org.eclipse.aether.RepositoryEvent.EventType;
import org.eclipse.aether.internal.impl.filter.DefaultRemoteRepositoryFilterManager;
import org.eclipse.aether.internal.impl.filter.Filters;
import org.eclipse.aether.internal.test.util.TestFileUtils;
Expand Down Expand Up @@ -71,6 +73,8 @@ public class DefaultMetadataResolverTest {

private DefaultRemoteRepositoryFilterManager remoteRepositoryFilterManager;

private RecordingRepositoryListener listener;

@Before
public void setup() throws Exception {
remoteRepositoryFilterSources = new HashMap<>();
Expand All @@ -95,6 +99,9 @@ public void setup() throws Exception {
metadata = new DefaultMetadata("gid", "aid", "ver", "maven-metadata.xml", Metadata.Nature.RELEASE_OR_SNAPSHOT);
connector = new RecordingRepositoryConnector();
connectorProvider.setConnector(connector);

listener = new RecordingRepositoryListener();
session.setRepositoryListener(listener);
}

@After
Expand Down Expand Up @@ -150,6 +157,21 @@ public void testResolve() throws IOException {
((TestLocalRepositoryManager) session.getLocalRepositoryManager()).getMetadataRegistration();
assertTrue(metadataRegistration.contains(metadata));
assertEquals(1, metadataRegistration.size());

List<RepositoryEvent> events =
listener.getEvents(EventType.METADATA_DOWNLOADING, EventType.METADATA_DOWNLOADED);
assertEquals(2, events.size());
assertSame(events.get(0).getTrace(), events.get(1).getTrace());

RepositoryEvent event = events.get(0);
assertEquals(EventType.METADATA_DOWNLOADING, event.getType());
assertEquals(metadata, event.getMetadata());

event = events.get(1);
assertEquals(EventType.METADATA_DOWNLOADED, event.getType());
assertEquals(metadata, event.getMetadata());
assertNull(event.getException());
assertNotNull(event.getFile());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@
package org.eclipse.aether.internal.impl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import org.eclipse.aether.RepositoryEvent;
import org.eclipse.aether.RepositoryListener;
Expand All @@ -32,10 +36,14 @@
*/
class RecordingRepositoryListener implements RepositoryListener {

private List<RepositoryEvent> events = Collections.synchronizedList(new ArrayList<RepositoryEvent>());
private final List<RepositoryEvent> events = Collections.synchronizedList(new ArrayList<>());

public List<RepositoryEvent> getEvents() {
return events;
public List<RepositoryEvent> getEvents(RepositoryEvent.EventType... types) {
if (types == null || types.length == 0) {
return events;
}
Set<RepositoryEvent.EventType> requiredTypes = EnumSet.copyOf(Arrays.asList(types));
return events.stream().filter(e -> requiredTypes.contains(e.getType())).collect(Collectors.toList());
}

public void clear() {
Expand Down

0 comments on commit 7d17bc3

Please sign in to comment.