Skip to content

Commit

Permalink
apache#2819 Add testAppliesTo at RuleTest
Browse files Browse the repository at this point in the history
  • Loading branch information
seoeun25 authored and navis committed Nov 20, 2019
1 parent bd10a4f commit 4a1ec1c
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import com.google.common.collect.ImmutableMap;
import io.druid.client.DruidServer;
import io.druid.jackson.DefaultObjectMapper;
import io.druid.timeline.DataSegment;
import org.joda.time.DateTime;
import org.joda.time.Interval;
import org.junit.Assert;
import org.junit.Test;
Expand All @@ -31,6 +33,10 @@
*/
public class IntervalLoadRuleTest
{
private final static DataSegment.Builder builder = DataSegment.builder()
.dataSource("test")
.version(new DateTime().toString());

@Test
public void testSerde() throws Exception
{
Expand Down Expand Up @@ -77,4 +83,47 @@ public void testMappingNullTieredReplicants() throws Exception{
IntervalLoadRule expectedIntervalLoadRule = jsonMapper.readValue(expectedJson, IntervalLoadRule.class);
Assert.assertEquals(expectedIntervalLoadRule, inputIntervalLoadRule);
}

@Test
public void testAppliesTo()
{
DateTime now = new DateTime("2019-11-01T07:05:58");
IntervalLoadRule rule = new IntervalLoadRule(
new Interval("2019-11-01T05:00:00.000Z/2019-11-01T07:00:00.000Z"), null
);

Assert.assertFalse(
rule.appliesTo(
builder.interval(
new Interval("2019-11-01T04:00:00.000Z/2019-11-01T05:00:00.000Z")
).build(),
now
)
);
Assert.assertTrue(
rule.appliesTo(
builder.interval(
new Interval("2019-11-01T05:00:00.000Z/2019-11-01T06:00:00.000Z")
).build(),
now
)
);
Assert.assertTrue(
rule.appliesTo(
builder.interval(
new Interval("2019-11-01T06:00:00.000Z/2019-11-01T07:00:00.000Z")
).build(),
now
)
);
Assert.assertFalse(
rule.appliesTo(
builder.interval(
new Interval("2019-11-01T07:00:00.000Z/2019-11-01T08:00:00.000Z")
).build(),
now
)
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,48 @@ public void testAppliesToPeriod()
)
);
}

@Test
public void testAppliesTo()
{
DateTime now = new DateTime("2019-11-01T07:05:58");
PeriodDropRule rule = new PeriodDropRule(
new Period("PT2H")
);

Assert.assertFalse(
rule.appliesTo(
builder.interval(
new Interval("2019-11-01T04:00:00.000Z/2019-11-01T05:00:00.000Z")
).build(),
now
)
);
Assert.assertFalse(
rule.appliesTo(
builder.interval(
new Interval("2019-11-01T05:00:00.000Z/2019-11-01T06:00:00.000Z")
).build(),
now
)
);
Assert.assertTrue(
rule.appliesTo(
builder.interval(
new Interval("2019-11-01T06:00:00.000Z/2019-11-01T07:00:00.000Z")
).build(),
now
)
);

Assert.assertFalse(
rule.appliesTo(
builder.interval(
new Interval("2019-11-01T07:00:00.000Z/2019-11-01T08:00:00.000Z")
).build(),
now
)
);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,49 @@ public void testMappingNullTieredReplicants() throws Exception{
Assert.assertEquals(expectedPeriodLoadRule.getTieredReplicants(), inputPeriodLoadRule.getTieredReplicants());
Assert.assertEquals(expectedPeriodLoadRule.getPeriod(), inputPeriodLoadRule.getPeriod());
}

@Test
public void testAppliesTo()
{
DateTime now = new DateTime("2019-11-01T07:05:58");
PeriodLoadRule rule = new PeriodLoadRule(
new Period("PT2H"),
ImmutableMap.<String, Integer>of("", 0)
);

Assert.assertFalse(
rule.appliesTo(
builder.interval(
new Interval("2019-11-01T04:00:00.000Z/2019-11-01T05:00:00.000Z")
).build(),
now
)
);
Assert.assertFalse(
rule.appliesTo(
builder.interval(
new Interval("2019-11-01T05:00:00.000Z/2019-11-01T06:00:00.000Z")
).build(),
now
)
);
Assert.assertTrue(
rule.appliesTo(
builder.interval(
new Interval("2019-11-01T06:00:00.000Z/2019-11-01T07:00:00.000Z")
).build(),
now
)
);

Assert.assertTrue(
rule.appliesTo(
builder.interval(
new Interval("2019-11-01T07:00:00.000Z/2019-11-01T08:00:00.000Z")
).build(),
now
)
);

}
}

0 comments on commit 4a1ec1c

Please sign in to comment.