Search in sources :

Example 6 with CustomTimeBucket

use of org.apache.apex.malhar.lib.appdata.schemas.CustomTimeBucket in project apex-malhar by apache.

the class CustomTimeBucketRegistryTest method testBuildingRegistry.

@Test
public void testBuildingRegistry() {
    CustomTimeBucketRegistry timeBucketRegistry = new CustomTimeBucketRegistry();
    CustomTimeBucket c1m = new CustomTimeBucket(TimeBucket.MINUTE);
    CustomTimeBucket c1h = new CustomTimeBucket(TimeBucket.HOUR);
    CustomTimeBucket c1d = new CustomTimeBucket(TimeBucket.DAY);
    timeBucketRegistry.register(c1m, TimeBucket.MINUTE.ordinal());
    timeBucketRegistry.register(c1h, TimeBucket.HOUR.ordinal());
    timeBucketRegistry.register(c1d, TimeBucket.DAY.ordinal());
    CustomTimeBucket customTimeBucket = timeBucketRegistry.getTimeBucket(TimeBucket.MINUTE.ordinal());
    Assert.assertTrue(customTimeBucket.isUnit());
    Assert.assertEquals(TimeBucket.MINUTE, customTimeBucket.getTimeBucket());
    customTimeBucket = timeBucketRegistry.getTimeBucket(TimeBucket.HOUR.ordinal());
    Assert.assertTrue(customTimeBucket.isUnit());
    Assert.assertEquals(TimeBucket.HOUR, customTimeBucket.getTimeBucket());
    customTimeBucket = timeBucketRegistry.getTimeBucket(TimeBucket.DAY.ordinal());
    Assert.assertTrue(customTimeBucket.isUnit());
    Assert.assertEquals(TimeBucket.DAY, customTimeBucket.getTimeBucket());
    Assert.assertEquals(TimeBucket.MINUTE.ordinal(), (int) timeBucketRegistry.getTimeBucketId(c1m));
    Assert.assertEquals(TimeBucket.HOUR.ordinal(), (int) timeBucketRegistry.getTimeBucketId(c1h));
    Assert.assertEquals(TimeBucket.DAY.ordinal(), (int) timeBucketRegistry.getTimeBucketId(c1d));
}
Also used : CustomTimeBucket(org.apache.apex.malhar.lib.appdata.schemas.CustomTimeBucket) CustomTimeBucketRegistry(org.apache.apex.malhar.lib.dimensions.CustomTimeBucketRegistry) Test(org.junit.Test)

Example 7 with CustomTimeBucket

use of org.apache.apex.malhar.lib.appdata.schemas.CustomTimeBucket in project apex-malhar by apache.

the class CustomTimeBucketRegistryTest method testRegister.

@Test
public void testRegister() {
    CustomTimeBucketRegistry timeBucketRegistry = new CustomTimeBucketRegistry();
    CustomTimeBucket c1m = new CustomTimeBucket(TimeBucket.MINUTE);
    CustomTimeBucket c1h = new CustomTimeBucket(TimeBucket.HOUR);
    CustomTimeBucket c1d = new CustomTimeBucket(TimeBucket.DAY);
    timeBucketRegistry.register(c1m, TimeBucket.MINUTE.ordinal());
    timeBucketRegistry.register(c1h, TimeBucket.HOUR.ordinal());
    timeBucketRegistry.register(c1d, TimeBucket.DAY.ordinal());
    int max = Integer.MIN_VALUE;
    max = Math.max(max, TimeBucket.MINUTE.ordinal());
    max = Math.max(max, TimeBucket.HOUR.ordinal());
    max = Math.max(max, TimeBucket.DAY.ordinal());
    CustomTimeBucket c5m = new CustomTimeBucket(TimeBucket.MINUTE, 5L);
    timeBucketRegistry.register(c5m);
    int timeBucketId = timeBucketRegistry.getTimeBucketId(c5m);
    Assert.assertEquals(max + 1, timeBucketId);
}
Also used : CustomTimeBucket(org.apache.apex.malhar.lib.appdata.schemas.CustomTimeBucket) Test(org.junit.Test)

Example 8 with CustomTimeBucket

use of org.apache.apex.malhar.lib.appdata.schemas.CustomTimeBucket in project apex-malhar by apache.

the class CustomTimeBucketRegistryTest method testBuildingRegistry.

@Test
public void testBuildingRegistry() {
    CustomTimeBucketRegistry timeBucketRegistry = new CustomTimeBucketRegistry();
    CustomTimeBucket c1m = new CustomTimeBucket(TimeBucket.MINUTE);
    CustomTimeBucket c1h = new CustomTimeBucket(TimeBucket.HOUR);
    CustomTimeBucket c1d = new CustomTimeBucket(TimeBucket.DAY);
    timeBucketRegistry.register(c1m, TimeBucket.MINUTE.ordinal());
    timeBucketRegistry.register(c1h, TimeBucket.HOUR.ordinal());
    timeBucketRegistry.register(c1d, TimeBucket.DAY.ordinal());
    CustomTimeBucket customTimeBucket = timeBucketRegistry.getTimeBucket(TimeBucket.MINUTE.ordinal());
    Assert.assertTrue(customTimeBucket.isUnit());
    Assert.assertEquals(TimeBucket.MINUTE, customTimeBucket.getTimeBucket());
    customTimeBucket = timeBucketRegistry.getTimeBucket(TimeBucket.HOUR.ordinal());
    Assert.assertTrue(customTimeBucket.isUnit());
    Assert.assertEquals(TimeBucket.HOUR, customTimeBucket.getTimeBucket());
    customTimeBucket = timeBucketRegistry.getTimeBucket(TimeBucket.DAY.ordinal());
    Assert.assertTrue(customTimeBucket.isUnit());
    Assert.assertEquals(TimeBucket.DAY, customTimeBucket.getTimeBucket());
    Assert.assertEquals(TimeBucket.MINUTE.ordinal(), (int) timeBucketRegistry.getTimeBucketId(c1m));
    Assert.assertEquals(TimeBucket.HOUR.ordinal(), (int) timeBucketRegistry.getTimeBucketId(c1h));
    Assert.assertEquals(TimeBucket.DAY.ordinal(), (int) timeBucketRegistry.getTimeBucketId(c1d));
}
Also used : CustomTimeBucket(org.apache.apex.malhar.lib.appdata.schemas.CustomTimeBucket) Test(org.junit.Test)

Example 9 with CustomTimeBucket

use of org.apache.apex.malhar.lib.appdata.schemas.CustomTimeBucket in project apex-malhar by apache.

the class CustomTimeBucketRegistryTest method testRegister.

@Test
public void testRegister() {
    CustomTimeBucketRegistry timeBucketRegistry = new CustomTimeBucketRegistry();
    CustomTimeBucket c1m = new CustomTimeBucket(TimeBucket.MINUTE);
    CustomTimeBucket c1h = new CustomTimeBucket(TimeBucket.HOUR);
    CustomTimeBucket c1d = new CustomTimeBucket(TimeBucket.DAY);
    timeBucketRegistry.register(c1m, TimeBucket.MINUTE.ordinal());
    timeBucketRegistry.register(c1h, TimeBucket.HOUR.ordinal());
    timeBucketRegistry.register(c1d, TimeBucket.DAY.ordinal());
    int max = Integer.MIN_VALUE;
    max = Math.max(max, TimeBucket.MINUTE.ordinal());
    max = Math.max(max, TimeBucket.HOUR.ordinal());
    max = Math.max(max, TimeBucket.DAY.ordinal());
    CustomTimeBucket c5m = new CustomTimeBucket(TimeBucket.MINUTE, 5L);
    timeBucketRegistry.register(c5m);
    int timeBucketId = timeBucketRegistry.getTimeBucketId(c5m);
    Assert.assertEquals(max + 1, timeBucketId);
}
Also used : CustomTimeBucket(org.apache.apex.malhar.lib.appdata.schemas.CustomTimeBucket) CustomTimeBucketRegistry(org.apache.apex.malhar.lib.dimensions.CustomTimeBucketRegistry) Test(org.junit.Test)

Aggregations

CustomTimeBucket (org.apache.apex.malhar.lib.appdata.schemas.CustomTimeBucket)9 Test (org.junit.Test)5 CustomTimeBucketRegistry (org.apache.apex.malhar.lib.dimensions.CustomTimeBucketRegistry)2 GPOMutable (org.apache.apex.malhar.lib.appdata.gpo.GPOMutable)1 Fields (org.apache.apex.malhar.lib.appdata.schemas.Fields)1 EventKey (org.apache.apex.malhar.lib.dimensions.DimensionsEvent.EventKey)1