-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
272 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...t/jpastreamer/termopoptimizer/standard/StandardTerminalOperationOptimizerFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.speedment.jpastreamer.termopoptimizer.standard; | ||
|
||
import com.speedment.jpastreamer.termopoptimizer.TerminalOperationOptimizerFactory; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
final class StandardTerminalOperationOptimizerFactoryTest { | ||
|
||
@Test | ||
void get() { | ||
final TerminalOperationOptimizerFactory terminalOperationOptimizerFactory = new StandardTerminalOperationOptimizerFactory(); | ||
assertNotNull(terminalOperationOptimizerFactory.get()); | ||
} | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
...c/test/java/com/speedment/jpastreamer/termopoptimizer/standard/internal/AnyMatchTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.speedment.jpastreamer.termopoptimizer.standard.internal; | ||
|
||
import com.speedment.jpastreamer.pipeline.Pipeline; | ||
|
||
import java.util.function.Predicate; | ||
import java.util.stream.Stream; | ||
|
||
final class AnyMatchTest extends StandardTerminalOperationOptimizerTest<String> { | ||
|
||
@Override | ||
Class<String> getEntityClass() { | ||
return String.class; | ||
} | ||
|
||
@Override | ||
protected Stream<PipelineTestCase<String>> pipelines() { | ||
return Stream.of( | ||
noAnyMatch(), | ||
anyMatch() | ||
); | ||
} | ||
|
||
private PipelineTestCase<String> noAnyMatch() { | ||
final Pipeline<String> noAnyMatch = createPipeline( | ||
tof.createAllMatch(s -> s.equals("test")), | ||
iof.createLimit(1) | ||
); | ||
|
||
final Pipeline<String> noAnyMatchExpected = createPipeline( | ||
tof.createAllMatch(s -> s.equals("test")), | ||
iof.createLimit(1) | ||
); | ||
|
||
return new PipelineTestCase<>("No Any Match", noAnyMatch, noAnyMatchExpected); | ||
} | ||
|
||
private PipelineTestCase<String> anyMatch() { | ||
final Predicate<String> p = s -> (s.equals("test")); | ||
|
||
final Pipeline<String> anyMatch = createPipeline( | ||
tof.createAnyMatch(p), | ||
iof.createLimit(100) | ||
); | ||
|
||
final Pipeline<String> anyMatchExpected = createPipeline( | ||
tof.createAnyMatch(s -> true), | ||
iof.createLimit(100), | ||
iof.createLimit(1), | ||
iof.createFilter(p) | ||
); | ||
|
||
return new PipelineTestCase<>("Any Match", anyMatch, anyMatchExpected); | ||
} | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
...rc/test/java/com/speedment/jpastreamer/termopoptimizer/standard/internal/FindAnyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.speedment.jpastreamer.termopoptimizer.standard.internal; | ||
|
||
public class FindAnyTest { | ||
} |
4 changes: 4 additions & 0 deletions
4
.../test/java/com/speedment/jpastreamer/termopoptimizer/standard/internal/FindFirstTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.speedment.jpastreamer.termopoptimizer.standard.internal; | ||
|
||
public class FindFirstTest { | ||
} |
4 changes: 4 additions & 0 deletions
4
.../test/java/com/speedment/jpastreamer/termopoptimizer/standard/internal/NoneMatchTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.speedment.jpastreamer.termopoptimizer.standard.internal; | ||
|
||
public class NoneMatchTest { | ||
} |
105 changes: 105 additions & 0 deletions
105
...jpastreamer/termopoptimizer/standard/internal/StandardTerminalOperationOptimizerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package com.speedment.jpastreamer.termopoptimizer.standard.internal; | ||
|
||
import com.speedment.jpastreamer.pipeline.Pipeline; | ||
import com.speedment.jpastreamer.pipeline.PipelineFactory; | ||
import com.speedment.jpastreamer.pipeline.intermediate.IntermediateOperation; | ||
import com.speedment.jpastreamer.pipeline.intermediate.IntermediateOperationFactory; | ||
import com.speedment.jpastreamer.pipeline.terminal.TerminalOperation; | ||
import com.speedment.jpastreamer.pipeline.terminal.TerminalOperationFactory; | ||
import com.speedment.jpastreamer.rootfactory.RootFactory; | ||
import com.speedment.jpastreamer.termopoptimizer.TerminalOperationOptimizer; | ||
import org.junit.jupiter.api.DynamicTest; | ||
import org.junit.jupiter.api.TestFactory; | ||
|
||
import java.util.List; | ||
import java.util.ServiceLoader; | ||
import java.util.stream.Stream; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertArrayEquals; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.DynamicTest.dynamicTest; | ||
|
||
abstract class StandardTerminalOperationOptimizerTest<ENTITY> { | ||
|
||
protected final PipelineFactory pipelineFactory = RootFactory.getOrThrow(PipelineFactory.class, ServiceLoader::load); | ||
protected final IntermediateOperationFactory iof = RootFactory.getOrThrow(IntermediateOperationFactory.class, ServiceLoader::load); | ||
protected final TerminalOperationFactory tof = RootFactory.getOrThrow(TerminalOperationFactory.class, ServiceLoader::load); | ||
protected final TerminalOperationOptimizer optimizer = new StandardTerminalOperationOptimizer(); | ||
|
||
abstract Class<ENTITY> getEntityClass(); | ||
|
||
@TestFactory | ||
Stream<DynamicTest> optimize() { | ||
return pipelines().map(testCase -> dynamicTest(testCase.getName(), () -> { | ||
this.optimizer.optimize(testCase.getPipeline()); | ||
|
||
assertTestCase(testCase); | ||
})); | ||
} | ||
|
||
protected abstract Stream<PipelineTestCase<ENTITY>> pipelines(); | ||
|
||
protected Pipeline<ENTITY> createPipeline(final TerminalOperation<?, ?> terminalOperation, final IntermediateOperation<?, ?>... operations) { | ||
final Pipeline<ENTITY> pipeline = pipelineFactory.createPipeline(getEntityClass()); | ||
|
||
for (IntermediateOperation<?, ?> operation : operations) { | ||
pipeline.intermediateOperations().add(operation); | ||
} | ||
|
||
pipeline.terminatingOperation(terminalOperation); | ||
|
||
return pipeline; | ||
} | ||
|
||
private void assertTestCase(final PipelineTestCase<ENTITY> testCase) { | ||
final Pipeline<ENTITY> unoptimized = testCase.getPipeline(); | ||
final Pipeline<ENTITY> optimized = testCase.getExpectedPipeline(); | ||
|
||
final List<IntermediateOperation<?, ?>> unoptimizedIntermediateOperations = unoptimized.intermediateOperations(); | ||
final List<IntermediateOperation<?, ?>> optimizedIntermediateOperations = optimized.intermediateOperations(); | ||
|
||
assertEquals(optimizedIntermediateOperations.size(), unoptimizedIntermediateOperations.size()); | ||
|
||
for (int i = 0; i < unoptimizedIntermediateOperations.size(); i++) { | ||
final IntermediateOperation<?, ?> unoptimizedOperation = unoptimizedIntermediateOperations.get(i); | ||
final IntermediateOperation<?, ?> optimizedOperation = optimizedIntermediateOperations.get(i); | ||
|
||
assertEquals(optimizedOperation.type(), unoptimizedOperation.type()); | ||
assertArguments(optimizedOperation.arguments(), unoptimizedOperation.arguments()); | ||
} | ||
} | ||
|
||
protected void assertArguments(final Object[] expected, final Object[] actual) { | ||
assertArrayEquals(expected, actual); | ||
} | ||
|
||
protected static final class PipelineTestCase<ENTITY> { | ||
|
||
private final String name; | ||
private final Pipeline<ENTITY> pipeline; | ||
private final Pipeline<ENTITY> expectedPipeline; | ||
|
||
protected PipelineTestCase( | ||
final String name, | ||
final Pipeline<ENTITY> pipeline, | ||
final Pipeline<ENTITY> expectedPipeline | ||
) { | ||
this.name = name; | ||
this.pipeline = pipeline; | ||
this.expectedPipeline = expectedPipeline; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public Pipeline<ENTITY> getPipeline() { | ||
return pipeline; | ||
} | ||
|
||
public Pipeline<ENTITY> getExpectedPipeline() { | ||
return expectedPipeline; | ||
} | ||
} | ||
|
||
} |