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

Refactor/misc #75

Merged
merged 4 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ subprojects {
homepage.set("https://github.com/zero88/scheduler.x")
}
testLogger {
slowThreshold = 5000
slowThreshold = 7000
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import org.jetbrains.annotations.Nullable;

import io.github.zero88.schedulerx.Task;
import io.github.zero88.schedulerx.spi.TriggerRepresentation;
import io.github.zero88.schedulerx.spi.TriggerRepresentationServiceLoader;
import io.github.zero88.schedulerx.trigger.repr.TriggerRepresentation;
import io.github.zero88.schedulerx.trigger.repr.TriggerRepresentationServiceLoader;
import io.github.zero88.schedulerx.trigger.rule.TriggerRule;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.zero88.schedulerx.spi;
package io.github.zero88.schedulerx.trigger.repr;

import org.jetbrains.annotations.NotNull;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.zero88.schedulerx.spi;
package io.github.zero88.schedulerx.trigger.repr;

import org.jetbrains.annotations.NotNull;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.zero88.schedulerx.spi;
package io.github.zero88.schedulerx.trigger.repr;

import org.jetbrains.annotations.NotNull;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.zero88.schedulerx.spi;
package io.github.zero88.schedulerx.trigger.repr;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.zero88.schedulerx.spi;
package io.github.zero88.schedulerx.trigger.repr;

import java.util.Locale;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.zero88.schedulerx.spi;
package io.github.zero88.schedulerx.trigger.repr;

import java.util.function.Function;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.zero88.schedulerx.spi;
package io.github.zero88.schedulerx.trigger.repr;

import java.util.Map;
import java.util.stream.Collectors;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* Provides the classes and interfaces to represent the trigger in human language.
*/

package io.github.zero88.schedulerx.trigger.repr;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* Provides the classes and interfaces to add advanced trigger rules.
*/

package io.github.zero88.schedulerx.trigger.rule;
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.TimeZone;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import io.github.zero88.schedulerx.trigger.rule.Timeframe;
import io.github.zero88.schedulerx.trigger.rule.TriggerRule;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

Expand Down Expand Up @@ -95,10 +99,23 @@ void test_preview_trigger() {
final PreviewParameter parameter = new PreviewParameter().setStartedAt(startedAt.toInstant())
.setTimes(5)
.setTimeZone(ZoneOffset.UTC);
final List<OffsetDateTime> result = trigger.preview(parameter);
Assertions.assertEquals(5, result.size());
Assertions.assertIterableEquals(expected, result);
Assertions.assertEquals(startedAt.toInstant(), parameter.getStartedAt());
Assertions.assertIterableEquals(expected, trigger.preview(parameter));
}

@Test
void test_preview_trigger_with_rule() {
final Instant startedAt = OffsetDateTime.parse("2023-10-01T23:00:00Z").toInstant();
final List<OffsetDateTime> expected = Arrays.asList(OffsetDateTime.parse("2023-10-03T22:00:00Z"),
OffsetDateTime.parse("2023-10-04T22:00:00Z"));

final CronTrigger trigger = CronTrigger.builder().expression("0 0 22 ? * * *").build();
final TriggerRule rule = TriggerRule.create(Collections.singletonList(
Timeframe.of(Instant.parse("2023-10-03T00:00:00Z"),
Instant.parse("2023-10-06T00:00:00Z"))),
Instant.parse("2023-10-05T00:00:00Z"));
final PreviewParameter parameter = PreviewParameter.byDefault().setStartedAt(startedAt).setRule(rule);
Assertions.assertIterableEquals(expected, trigger.preview(parameter));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.time.OffsetDateTime;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;
Expand All @@ -11,6 +12,9 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

import io.github.zero88.schedulerx.trigger.rule.Timeframe;
import io.github.zero88.schedulerx.trigger.rule.TriggerRule;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.exc.InvalidFormatException;
Expand Down Expand Up @@ -98,9 +102,30 @@ void test_preview_trigger() {
final PreviewParameter parameter = PreviewParameter.byDefault()
.setStartedAt(startedAt.toInstant())
.setTimeZone(TimeZone.getTimeZone("Asia/Ho_Chi_Minh"));
final List<OffsetDateTime> result = trigger.preview(parameter);
Assertions.assertEquals(3, result.size());
Assertions.assertIterableEquals(expected, result);
Assertions.assertIterableEquals(expected, trigger.preview(parameter));
}

@Test
void test_preview_trigger_with_rule() {
final OffsetDateTime startedAt = OffsetDateTime.parse("2023-07-30T18:01+07:00");
final List<OffsetDateTime> expected = Arrays.asList(OffsetDateTime.parse("2023-07-30T19:01:00+07:00"),
OffsetDateTime.parse("2023-07-30T19:31:00+07:00"),
OffsetDateTime.parse("2023-07-30T20:01:00+07:00"),
OffsetDateTime.parse("2023-07-30T20:31:00+07:00"));

final IntervalTrigger trigger = IntervalTrigger.builder()
.interval(30)
.intervalTimeUnit(TimeUnit.MINUTES)
.build();
final TriggerRule rule = TriggerRule.create(Collections.singletonList(
Timeframe.of(OffsetDateTime.parse("2023-07-30T19:00:00+07:00"),
OffsetDateTime.parse("2023-07-31T00:00:00+07:00"))),
OffsetDateTime.parse("2023-07-30T21:00:00+07:00").toInstant());
final PreviewParameter parameter = PreviewParameter.byDefault()
.setStartedAt(startedAt.toInstant())
.setTimeZone(TimeZone.getTimeZone("Asia/Ho_Chi_Minh"))
.setRule(rule);
Assertions.assertIterableEquals(expected, trigger.preview(parameter));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,21 @@ void test_byDefault() {
Assertions.assertNotNull(parameter.getRule());
}


@Test
void test_byConstructor() {
final PreviewParameter parameter = new PreviewParameter();
Assertions.assertEquals(1, parameter.getTimes());
Assertions.assertNotNull(parameter.getStartedAt());
Assertions.assertNull(parameter.getTimeZone());
Assertions.assertNotNull(parameter.getRule());
}

@ParameterizedTest
@CsvSource({ "31,30", "-1,1", "0,1", "10,10", "15,15" })
void test_min_max_times(int input, int expected) {
Assertions.assertEquals(expected, PreviewParameter.byDefault().setTimes(input).getTimes());
Assertions.assertEquals(expected, new PreviewParameter().setTimes(input).getTimes());
}

@ParameterizedTest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package io.github.zero88.schedulerx.spi;
package io.github.zero88.schedulerx.trigger.repr;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import io.github.zero88.schedulerx.trigger.CronTrigger;
import io.github.zero88.schedulerx.trigger.repr.CronTriggerRepresentationMapper;
import io.github.zero88.schedulerx.trigger.repr.TriggerRepresentation;

public class CronTriggerRepresentationExample implements CronTriggerRepresentationMapper {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.zero88.schedulerx.spi;
package io.github.zero88.schedulerx.trigger.repr;

import static org.junit.jupiter.params.provider.Arguments.arguments;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.github.zero88.schedulerx.trigger.repr.CronTriggerRepresentationExample
2 changes: 0 additions & 2 deletions lombok.config

This file was deleted.