Skip to content
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

@W-17808637 Improving code coverage for core/internal module #14244

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
7cce1cd
Removed duplicate classes and consolidated tests
chris-ebert Feb 19, 2025
6587d7c
Merge branch 'master' into W-17808637/improve_coverage
chris-ebert Feb 19, 2025
525b5d9
Merge branch 'master' into W-17808637/improve_coverage
chris-ebert Mar 6, 2025
024864d
Added tests for coverage
chris-ebert Mar 6, 2025
6003669
Merge branch 'master' into W-17808637/improve_coverage
chris-ebert Mar 6, 2025
67c6237
Merge branch 'master' into W-17808637/improve_coverage
chris-ebert Mar 11, 2025
a51fe2f
More tests
chris-ebert Mar 11, 2025
d0551ab
Added more tests
chris-ebert Mar 11, 2025
9ed975e
Added more tests
chris-ebert Mar 12, 2025
d62b053
Added some basic coverage for the builders.
chris-ebert Mar 13, 2025
dd43bb4
Argh. More tests - coverage going up but not there yet.
chris-ebert Mar 14, 2025
f628ea4
Renamed tests to conform to convention
chris-ebert Mar 14, 2025
e6b4716
Added more tests. Refactored a tiny bit to make code more testable
chris-ebert Mar 15, 2025
a3ae9b4
Hooray. Coverage over 80%
chris-ebert Mar 17, 2025
674226e
Merged two test classes that were testing the same thing.
chris-ebert Mar 18, 2025
38f51f6
Fixed names of tests to conform with convention
chris-ebert Mar 18, 2025
01cdb9a
Review item: reverted indirection for decorator constructor.
chris-ebert Mar 18, 2025
ef0a6f7
Merge branch 'master' into W-17808637/improve_coverage
chris-ebert Mar 18, 2025
d2926c3
W-17607446: Handle missing fields in DefaultMessageBuilder (#14281)
d4nielyan9 Mar 18, 2025
b08355f
W-17802891: [Windows] Fix race condition on LeakedThread by using lat…
lbarrios Mar 18, 2025
a10b628
W-18023026: add delegate methods for sse (#14291)
marianogonzalez Mar 19, 2025
571ff54
W-17068193: Replace uses of javax.inject with jakarta.inject in Mule…
elrodro83 Mar 19, 2025
fde9ca1
Added some basic coverage for the builders.
chris-ebert Mar 13, 2025
3c7df81
Updates from review
chris-ebert Mar 19, 2025
d7dd524
W-17774312: Move ArtifactDeclaration uses from spring-config to tooli…
elrodro83 Mar 19, 2025
c0e899d
W-17068193: Replace uses of javax.inject with jakarta.inject in Mule…
elrodro83 Mar 19, 2025
b69a296
Updates from review
chris-ebert Mar 19, 2025
1c78012
Merge branch 'master' into W-17808637/improve_coverage
chris-ebert Mar 19, 2025
fd5f52e
Review: inject is supposed to be transient... so don't declare it here.
chris-ebert Mar 19, 2025
6b7f772
Review: Added comments to tests
chris-ebert Mar 19, 2025
ef8a681
Merge branch 'master' into W-17808637/improve_coverage
chris-ebert Mar 21, 2025
3f751b7
Added some checks where SonarQube was complaining.
chris-ebert Mar 24, 2025
605e3f3
Added some basic coverage for the builders.
chris-ebert Mar 13, 2025
f71df17
W-17774312: Move ArtifactDeclaration uses from spring-config to tooli…
elrodro83 Mar 19, 2025
94ebc08
Fixed the test assert to allow for multiple calls of apply (some vers…
chris-ebert Mar 25, 2025
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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
* license, a copy of which has been included with this distribution in the
* LICENSE.txt file.
*/
package org.mule.runtime.core.internal.util.java;
package org.mule.runtime.core.internal.util.version;

import static org.mule.runtime.core.internal.util.java.JdkVersionUtils.isRecommendedJdkVersion;
import static org.mule.runtime.core.internal.util.java.JdkVersionUtils.isSupportedJdkVersion;
import static org.mule.runtime.core.internal.util.version.JdkVersionUtils.isRecommendedJdkVersion;
import static org.mule.runtime.core.internal.util.version.JdkVersionUtils.isSupportedJdkVersion;
import static org.mule.runtime.manifest.api.MuleManifest.getMuleManifest;
import static org.mule.test.allure.AllureConstants.SupportedEnvironmentsFeature.SUPPORTED_ENVIRONMENTS;
import static org.mule.test.allure.AllureConstants.SupportedEnvironmentsFeature.JdkVersionStory.JDK_VERSION;
Expand All @@ -26,8 +26,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import org.mule.runtime.core.internal.util.java.JdkVersionUtils.JdkVersion;
import org.mule.runtime.core.internal.util.version.JdkVersionUtils;
import org.mule.runtime.core.internal.util.version.JdkVersionUtils.JdkVersion;
import org.mule.runtime.manifest.internal.DefaultMuleManifest;
import org.mule.tck.junit4.AbstractMuleTestCase;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;

import org.mule.tck.junit4.AbstractMuleTestCase;

import org.junit.Test;

import java.util.List;

public class VersionRangeTestCase extends AbstractMuleTestCase {

@Test
Expand Down Expand Up @@ -71,6 +77,79 @@ public void invalidRange() {
assertThrows(IllegalArgumentException.class, () -> new VersionRange("saraza"));
}

@Test
public void testSingleVersionRange() {
VersionRange vr = new VersionRange("[1.5.0_11,1.6)");
assertNotNull(vr);
assertTrue(vr.isLowerBoundInclusive());
assertFalse(vr.isUpperBoundInclusive());
assertEquals("1.5.0_11", vr.getLowerVersion());
assertEquals("1.6", vr.getUpperVersion());

vr = new VersionRange("(1.5.0_11-b05,2.7.12]");
assertNotNull(vr);
assertFalse(vr.isLowerBoundInclusive());
assertTrue(vr.isUpperBoundInclusive());
assertEquals("1.5.0_11-b05", vr.getLowerVersion());
assertEquals("2.7.12", vr.getUpperVersion());
}

@Test
public void testCreateVersionRanges() {
List<VersionRange> ranges = VersionRange.createVersionRanges("(,1.4.2),[1.5.0_11,1.6),[1.7,]");
assertNotNull(ranges);
assertEquals(3, ranges.size());

VersionRange vr = ranges.get(0);
assertFalse(vr.isLowerBoundInclusive());
assertFalse(vr.isUpperBoundInclusive());
assertEquals("", vr.getLowerVersion());
assertEquals("1.4.2", vr.getUpperVersion());

vr = ranges.get(1);
assertTrue(vr.isLowerBoundInclusive());
assertFalse(vr.isUpperBoundInclusive());
assertEquals("1.5.0_11", vr.getLowerVersion());
assertEquals("1.6", vr.getUpperVersion());

vr = ranges.get(2);
assertTrue(vr.isLowerBoundInclusive());
assertTrue(vr.isUpperBoundInclusive());
assertEquals("1.7", vr.getLowerVersion());
assertEquals("", vr.getUpperVersion());
}

@Test(expected = IllegalArgumentException.class)
public void testInvalidDelimiter() {
VersionRange range = new VersionRange("{1.3,1.4.2)");
}

@Test(expected = IllegalArgumentException.class)
public void testMissingDelimiter() {
VersionRange range = new VersionRange("1.3,1.4.2)");
}

@Test(expected = IllegalArgumentException.class)
public void testInvalidVersion() {
VersionRange range = new VersionRange("[1.3,0,1.4.2)");
}

@Test(expected = IllegalArgumentException.class)
public void testInvalidCreateVersionRanges() {
List<VersionRange> ranges = VersionRange.createVersionRanges("(,1.4.2),1.5.0_11,1.6),[1.7,]");
for (VersionRange vr : ranges) {
System.out.println(vr);
}
}

@Test(expected = IllegalArgumentException.class)
public void testInvalidDelimiterCreateVersionRanges() {
List<VersionRange> ranges = VersionRange.createVersionRanges("(,1.4.2)|[1.5.0_11,1.6)|[1.7,]");
for (VersionRange vr : ranges) {
System.out.println(vr);
}
}

private void assertRangeContainsVersion(final VersionRange range, String version, boolean expected) {
assertThat("`" + version + "` " + (expected ? "not " : " ") + "contained in " + range.toString(),
range.contains(version), is(expected));
Expand Down
33 changes: 33 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -216,5 +216,38 @@
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -81,29 +81,6 @@ public void setSchedulerDecorator(Function<ScheduledExecutorService, ScheduledEx
this.schedulerDecorator = schedulerDecorator;
}

/**
Copy link
Author

Choose a reason for hiding this comment

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

Apparently nothing was using these methods... so yoink...

* Checks whether an error indicates that a thread pool is full.
*
* @param t the thrown error to analyze
* @return {@code true} if {@code t} indicates that a thread pool needed for the processing strategy owner rejected a task.
*/
protected boolean isSchedulerBusy(Throwable t) {
final Throwable cause = unwrap(t);
return RejectedExecutionException.class.isAssignableFrom(cause.getClass()) || isOverloadError(cause);
}

private boolean isOverloadError(final Throwable cause) {
if (cause instanceof MessagingException) {
return ((MessagingException) cause).getEvent().getError()
.map(e -> e.getErrorType())
.filter(errorType -> OVERLOAD.getName().equals(errorType.getIdentifier())
&& OVERLOAD.getNamespace().equals(errorType.getNamespace()))
.isPresent();
} else {
return false;
}
}

/**
* Extension of {@link Sink} using Reactor's {@link FluxSink} to accept events.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package org.mule.runtime.core.internal.processor.strategy;

import static java.lang.Thread.currentThread;
import static org.mule.runtime.core.api.construct.BackPressureReason.MAX_CONCURRENCY_EXCEEDED;
import static org.mule.runtime.core.api.processor.ReactiveProcessor.ProcessingType.CPU_LITE;
import static org.mule.runtime.core.api.processor.ReactiveProcessor.ProcessingType.CPU_LITE_ASYNC;
Expand Down Expand Up @@ -70,7 +71,7 @@ public abstract class AbstractReactorStreamProcessingStrategy extends AbstractSt
int parallelism,
int maxConcurrency,
boolean maxConcurrencyEagerCheck) {
super(subscribers, maxConcurrency, maxConcurrencyEagerCheck);
super(subscribers, maxConcurrency, maxConcurrencyEagerCheck, () -> currentThread());
Copy link
Author

Choose a reason for hiding this comment

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

Made this testable so I could check that interrupt was being passed on when interrupted...

this.cpuLightSchedulerSupplier = cpuLightSchedulerSupplier;
this.parallelism = parallelism;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,15 @@ abstract static class AbstractStreamProcessingStrategy extends AbstractProcessin
final protected int maxConcurrency;
final protected boolean maxConcurrencyEagerCheck;
final protected ClassLoader executionClassloader;
private final Supplier<Thread> threadSupplier;

protected AbstractStreamProcessingStrategy(int subscribers, int maxConcurrency, boolean maxConcurrencyEagerCheck) {
protected AbstractStreamProcessingStrategy(int subscribers, int maxConcurrency, boolean maxConcurrencyEagerCheck,
Supplier<Thread> threadSupplier) {
this.subscribers = requireNonNull(subscribers);
this.maxConcurrency = requireNonNull(maxConcurrency);
this.maxConcurrencyEagerCheck = maxConcurrency < MAX_VALUE && maxConcurrencyEagerCheck;
this.executionClassloader = currentThread().getContextClassLoader();
this.executionClassloader = threadSupplier.get().getContextClassLoader();
this.threadSupplier = threadSupplier;
}

protected void awaitSubscribersCompletion(FlowConstruct flowConstruct, final long shutdownTimeout,
Expand All @@ -147,7 +150,7 @@ protected void awaitSubscribersCompletion(FlowConstruct flowConstruct, final lon
}
}
} catch (InterruptedException e) {
currentThread().interrupt();
threadSupplier.get().interrupt();
if (getProperty(MULE_LIFECYCLE_FAIL_ON_FIRST_DISPOSE_ERROR) != null) {
throw new IllegalStateException(format("Subscribers of ProcessingStrategy for flow '%s' not completed before thread interruption",
flowConstruct.getName()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
import org.mule.runtime.core.api.processor.Sink;
import org.mule.runtime.core.api.processor.strategy.ProcessingStrategy;
import org.mule.runtime.core.api.processor.strategy.ProcessingStrategyFactory;
import org.mule.runtime.core.internal.processor.strategy.AbstractProcessingStrategy;
import org.mule.runtime.core.internal.processor.strategy.StreamPerEventSink;

/**
* Processing strategy that processes the {@link Pipeline} in the caller thread and does not schedule the processing of any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ class DirectSink implements Sink, Disposable {
public DirectSink(Function<Publisher<CoreEvent>, Publisher<CoreEvent>> function,
Consumer<CoreEvent> eventConsumer, int bufferSize) {
EmitterProcessor<CoreEvent> emitterProcessor = EmitterProcessor.create(bufferSize);
final reactor.core.Disposable disposable = emitterProcessor.transform(function).doOnError(throwable -> {
}).subscribe();
final reactor.core.Disposable disposable = emitterProcessor
.transform(function)
.doOnError(throwable -> {
})
.subscribe();
reactorSink = new DefaultReactorSink(emitterProcessor.sink(), millis -> disposable.dispose(), eventConsumer, bufferSize);
}

Expand Down
Loading