Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Jan 9, 2024
2 parents b1d4ee4 + e56b51f commit 00a9eb2
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@
* Returns already optimized XML if it's found in the cache.
*
* @since 0.28.11
* @todo #2674:30min The function {@code OptCached.contains(final XML xml)}
* isn't work properly. This function compares caching and compilation times,
* which may lead to erroneous results. We need to fix this.
* @todo #2746:30min Use checksum, not time.
* The following tests show that fetching from the cache doesn't work correctly:
* - {@link OptCachedTest#returnsFromCacheCorrectProgram(Path path)},
* - {@link OptCachedTest#returnsFromCacheButTimesSaveAndExecuteDifferent(Path path)}.
* Need to fix the file validation from cache: using checksum, but not time.
* Don't forget to enable the tests.
*/
public final class OptCached implements Optimization {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void returnsFromCacheIfXmlAlreadyInCache(@TempDir final Path tmp) throws IOExcep
final XML program = OptCachedTest.program(ZonedDateTime.now());
OptCachedTest.save(tmp, program);
MatcherAssert.assertThat(
"We expected that the program will be returned from the cache",
"We expected that the program will be returned from the cache.",
new OptCached(
path -> {
throw new IllegalStateException("This code shouldn't be executed");
Expand All @@ -74,6 +74,41 @@ void returnsFromCacheIfXmlAlreadyInCache(@TempDir final Path tmp) throws IOExcep
);
}

@Disabled
@Test
void returnsFromCacheButTimesSaveAndExecuteDifferent(@TempDir final Path tmp)
throws IOException {
final XML program = OptCachedTest.program(ZonedDateTime.now().minusMinutes(2));
OptCachedTest.save(tmp, program);
MatcherAssert.assertThat(
"We expected that the not immediately saved program will be returned from the cache.",
new OptCached(
path -> {
throw new IllegalStateException("This code shouldn't be executed");
},
tmp
).apply(program),
Matchers.equalTo(program)
);
}

@Disabled
@Test
void returnsFromCacheCorrectProgram(@TempDir final Path tmp)
throws IOException {
final XML prev = OptCachedTest.program(ZonedDateTime.now(), "first program");
OptCachedTest.save(tmp, prev);
final XML current = OptCachedTest.program(ZonedDateTime.now(), "second program");
MatcherAssert.assertThat(
"Expecting current program to be compiled, but prev program was returned from cache.",
new OptCached(
path -> current,
tmp
).apply(current),
Matchers.equalTo(current)
);
}

@Test
void optimizesIfXmlIsAbsentInCache(@TempDir final Path tmp) {
final XML program = OptCachedTest.program();
Expand Down Expand Up @@ -148,12 +183,23 @@ private static XML program() {
* @return XML representation of program.
*/
private static XML program(final ZonedDateTime time) {
return OptCachedTest.program(time, "same");
}

/**
* Generates EO program for tests with specified time and context.
* @param time Time.
* @param something String.
* @return XML representation of program.
*/
private static XML program(final ZonedDateTime time, final String something) {
return new XMLDocument(
new Xembler(
new Directives()
.add("program")
.attr("name", "main")
.attr("time", time.format(DateTimeFormatter.ISO_INSTANT))
.attr("something", something)
.up()
).xmlQuietly()
);
Expand Down

2 comments on commit 00a9eb2

@0pdd
Copy link

@0pdd 0pdd commented on 00a9eb2 Jan 9, 2024

Choose a reason for hiding this comment

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

Puzzle 2674-ddaefd43 disappeared from eo-maven-plugin/src/main/java/org/eolang/maven/optimization/OptCached.java), that's why I closed #2746. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

@0pdd
Copy link

@0pdd 0pdd commented on 00a9eb2 Jan 9, 2024

Choose a reason for hiding this comment

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

Puzzle 2746-c8b58fdb discovered in eo-maven-plugin/src/main/java/org/eolang/maven/optimization/OptCached.java) and submitted as #2764. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.