Skip to content
Open
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 THIRD-PARTY.txt
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ List of third-party dependencies grouped by their license type.

The GNU General Public License, v2 with Universal FOSS Exception, v1.0

* MySQL Connector/J (com.mysql:mysql-connector-j:9.6.0 - http://dev.mysql.com/doc/connector-j/en/)
* MySQL Connector/J (com.mysql:mysql-connector-j:9.7.0 - http://dev.mysql.com/doc/connector-j/en/)

Unicode-3.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@
package org.apache.stormcrawler.persistence;

import java.net.MalformedURLException;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.TimeZone;
import org.apache.commons.lang3.time.DateUtils;
import java.util.concurrent.TimeUnit;
import org.apache.stormcrawler.Metadata;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
Expand All @@ -41,18 +38,14 @@ void testScheduler() throws MalformedURLException {
scheduler.init(stormConf);
Metadata metadata = new Metadata();
metadata.addValue("testKey", "someValue");
Date before = new Date();
Optional<Date> nextFetch = scheduler.schedule(Status.FETCHED, metadata);
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.ROOT);
cal.add(Calendar.MINUTE, 360);
Assertions.assertEquals(
DateUtils.round(cal.getTime(), Calendar.SECOND),
DateUtils.round(nextFetch.get(), Calendar.SECOND));
Date after = new Date();
assertScheduleWithin(nextFetch, before, after, 360);
before = new Date();
nextFetch = scheduler.schedule(Status.ERROR, metadata);
cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.ROOT);
cal.add(Calendar.MINUTE, 3600);
Assertions.assertEquals(
DateUtils.round(cal.getTime(), Calendar.SECOND),
DateUtils.round(nextFetch.get(), Calendar.SECOND));
after = new Date();
assertScheduleWithin(nextFetch, before, after, 3600);
}

@Test
Expand All @@ -63,12 +56,10 @@ void testCustomWithDot() throws MalformedURLException {
scheduler.init(stormConf);
Metadata metadata = new Metadata();
metadata.addValue("testKey.key2", "someValue");
Date before = new Date();
Optional<Date> nextFetch = scheduler.schedule(Status.FETCHED, metadata);
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.ROOT);
cal.add(Calendar.MINUTE, 360);
Assertions.assertEquals(
DateUtils.round(cal.getTime(), Calendar.SECOND),
DateUtils.round(nextFetch.get(), Calendar.SECOND));
Date after = new Date();
assertScheduleWithin(nextFetch, before, after, 360);
}

@Test
Expand Down Expand Up @@ -107,4 +98,17 @@ void testSpecificNever() throws MalformedURLException {
Optional<Date> nextFetch = scheduler.schedule(Status.FETCHED, metadata);
Assertions.assertFalse(nextFetch.isPresent());
}

private static void assertScheduleWithin(
Optional<Date> nextFetch, Date beforeScheduling, Date afterScheduling, int minutes) {
Assertions.assertTrue(nextFetch.isPresent());
Date earliest = addMinutes(beforeScheduling, minutes);
Date lastest = addMinutes(afterScheduling, minutes);
Assertions.assertFalse(nextFetch.get().before(earliest));
Assertions.assertFalse(nextFetch.get().after(lastest));
}

private static Date addMinutes(Date date, int minutes) {
return new Date(date.getTime() + TimeUnit.MINUTES.toMillis(minutes));
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ under the License.
<jacoco.branchRatio>1.00</jacoco.branchRatio>
<jacoco.lineRatio>1.00</jacoco.lineRatio>
<jacoco.complexityRatio>1.00</jacoco.complexityRatio>
<mysql-connector-j>9.6.0</mysql-connector-j>
<mysql-connector-j>9.7.0</mysql-connector-j>

<skip.format.code>true</skip.format.code>

Expand Down