use of org.apereo.portal.concurrency.CallableWithoutResult in project uPortal by Jasig.
the class JpaDateTimeDimensionDaoTest method testGetMinMaxDateDimension.
@Test
public void testGetMinMaxDateDimension() {
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final DateDimension newestDateDimension = dateDimensionDao.getNewestDateDimension();
assertNull(newestDateDimension);
}
});
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final List<DateDimension> dateDimensions = dateDimensionDao.getDateDimensions();
assertEquals(Collections.EMPTY_LIST, dateDimensions);
}
});
this.executeInTransaction(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
DateMidnight date = new DateMidnight(2012, 1, 1);
for (int i = 0; i < 7; i++) {
dateDimensionDao.createDateDimension(date, 0, null);
date = date.plusDays(1);
}
}
});
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
DateMidnight date = new DateMidnight(2012, 1, 1);
final DateDimension dateDimension = dateDimensionDao.getDateDimensionByDate(date);
assertNotNull(dateDimension);
}
});
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final List<DateDimension> dateDimensions = dateDimensionDao.getDateDimensions();
assertEquals(7, dateDimensions.size());
}
});
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final DateMidnight start = new DateMidnight(2012, 1, 2);
final DateMidnight end = new DateMidnight(2012, 1, 6);
final List<DateDimension> dateDimensions = dateDimensionDao.getDateDimensionsBetween(start, end);
assertEquals(4, dateDimensions.size());
}
});
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final DateDimension oldestDateDimension = dateDimensionDao.getOldestDateDimension();
assertEquals(2012, oldestDateDimension.getYear());
assertEquals(1, oldestDateDimension.getMonth());
assertEquals(1, oldestDateDimension.getDay());
}
});
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final DateDimension newestDateDimension = dateDimensionDao.getNewestDateDimension();
assertEquals(2012, newestDateDimension.getYear());
assertEquals(1, newestDateDimension.getMonth());
assertEquals(7, newestDateDimension.getDay());
}
});
}
use of org.apereo.portal.concurrency.CallableWithoutResult in project uPortal by Jasig.
the class JpaEventAggregationManagementDaoTest method testAggregatedGroupConfig.
@Test
public void testAggregatedGroupConfig() throws Exception {
final IEntityGroup everyoneGroup = mock(IEntityGroup.class);
when(everyoneGroup.getServiceName()).thenReturn(new CompositeName("local"));
when(everyoneGroup.getName()).thenReturn("Everyone");
when(compositeGroupService.findGroup("local.0")).thenReturn(everyoneGroup);
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final AggregatedGroupConfig defaultAggregatedGroupConfig = eventAggregationManagementDao.getDefaultAggregatedGroupConfig();
assertNotNull(defaultAggregatedGroupConfig);
assertEquals(0, defaultAggregatedGroupConfig.getExcluded().size());
assertEquals(0, defaultAggregatedGroupConfig.getIncluded().size());
AggregatedGroupConfig loginAggregatedGroupConfig = eventAggregationManagementDao.getAggregatedGroupConfig(LoginPortalEventAggregator.class);
assertNull(loginAggregatedGroupConfig);
loginAggregatedGroupConfig = eventAggregationManagementDao.createAggregatedGroupConfig(LoginPortalEventAggregator.class);
assertNotNull(loginAggregatedGroupConfig);
assertEquals(0, loginAggregatedGroupConfig.getExcluded().size());
assertEquals(0, loginAggregatedGroupConfig.getIncluded().size());
final AggregatedGroupMapping group = aggregatedGroupLookupDao.getGroupMapping("local.0");
defaultAggregatedGroupConfig.getIncluded().add(group);
loginAggregatedGroupConfig.getExcluded().add(group);
eventAggregationManagementDao.updateAggregatedGroupConfig(defaultAggregatedGroupConfig);
eventAggregationManagementDao.updateAggregatedGroupConfig(loginAggregatedGroupConfig);
}
});
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final AggregatedGroupConfig defaultAggregatedGroupConfig = eventAggregationManagementDao.getDefaultAggregatedGroupConfig();
assertNotNull(defaultAggregatedGroupConfig);
assertEquals(0, defaultAggregatedGroupConfig.getExcluded().size());
assertEquals(1, defaultAggregatedGroupConfig.getIncluded().size());
AggregatedGroupConfig loginAggregatedGroupConfig = eventAggregationManagementDao.getAggregatedGroupConfig(LoginPortalEventAggregator.class);
assertNotNull(loginAggregatedGroupConfig);
assertEquals(1, loginAggregatedGroupConfig.getExcluded().size());
assertEquals(0, loginAggregatedGroupConfig.getIncluded().size());
eventAggregationManagementDao.deleteAggregatedGroupConfig(defaultAggregatedGroupConfig);
eventAggregationManagementDao.deleteAggregatedGroupConfig(loginAggregatedGroupConfig);
}
});
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final AggregatedGroupConfig defaultAggregatedGroupConfig = eventAggregationManagementDao.getDefaultAggregatedGroupConfig();
assertNotNull(defaultAggregatedGroupConfig);
assertEquals(0, defaultAggregatedGroupConfig.getExcluded().size());
assertEquals(0, defaultAggregatedGroupConfig.getIncluded().size());
AggregatedGroupConfig loginAggregatedGroupConfig = eventAggregationManagementDao.getAggregatedGroupConfig(LoginPortalEventAggregator.class);
assertNull(loginAggregatedGroupConfig);
}
});
}
use of org.apereo.portal.concurrency.CallableWithoutResult in project uPortal by Jasig.
the class JpaAggregatedGroupLookupDaoTest method testLoginAggregationLifecycle.
@Test
public void testLoginAggregationLifecycle() throws Exception {
final IEntityGroup everyoneGroup = mock(IEntityGroup.class);
when(everyoneGroup.getServiceName()).thenReturn(new CompositeName("local"));
when(everyoneGroup.getName()).thenReturn("Everyone");
when(compositeGroupService.findGroup("local.0")).thenReturn(everyoneGroup);
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final AggregatedGroupMapping groupMapping = aggregatedGroupLookupDao.getGroupMapping("local.0");
assertNotNull(groupMapping);
assertEquals("local", groupMapping.getGroupService());
assertEquals("Everyone", groupMapping.getGroupName());
}
});
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final AggregatedGroupMapping groupMapping = aggregatedGroupLookupDao.getGroupMapping("local.0");
assertNotNull(groupMapping);
assertEquals("local", groupMapping.getGroupService());
assertEquals("Everyone", groupMapping.getGroupName());
}
});
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final AggregatedGroupMapping groupMapping = aggregatedGroupLookupDao.getGroupMapping("local.2");
assertNotNull(groupMapping);
assertEquals("local", groupMapping.getGroupService());
assertEquals("2", groupMapping.getGroupName());
}
});
}
use of org.apereo.portal.concurrency.CallableWithoutResult in project uPortal by Jasig.
the class JpaBaseAggregationDaoTest method testBaseAggregationRangeQuery.
@Test
public final void testBaseAggregationRangeQuery() throws Exception {
final IEntityGroup entityGroupA = mock(IEntityGroup.class);
when(entityGroupA.getServiceName()).thenReturn(new CompositeName("local"));
when(entityGroupA.getName()).thenReturn("Group A");
when(compositeGroupService.findGroup("local.0")).thenReturn(entityGroupA);
final IEntityGroup entityGroupB = mock(IEntityGroup.class);
when(entityGroupB.getServiceName()).thenReturn(new CompositeName("local"));
when(entityGroupB.getName()).thenReturn("Group B");
when(compositeGroupService.findGroup("local.1")).thenReturn(entityGroupB);
final MutableInt aggrs = new MutableInt();
// Create 2 days of login aggregates ... every 5 minutes
final DateTime start = new DateTime(1326734644000l, DateTimeZone.UTC).minuteOfDay().roundFloorCopy();
final DateTime end = start.plusDays(2);
final AggregationInterval interval = AggregationInterval.FIVE_MINUTE;
final MutableObject startObj = new MutableObject();
final MutableObject endObj = new MutableObject();
this.executeInTransaction(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final Random r = new Random(0);
final AggregatedGroupMapping groupA = aggregatedGroupLookupDao.getGroupMapping("local.0");
final AggregatedGroupMapping groupB = aggregatedGroupLookupDao.getGroupMapping("local.1");
populateDateTimeDimensions(start, end, new FunctionWithoutResult<Tuple<DateDimension, TimeDimension>>() {
@Override
protected void applyWithoutResult(Tuple<DateDimension, TimeDimension> input) {
final TimeDimension td = input.second;
final DateDimension dd = input.first;
final DateTime instant = td.getTime().toDateTime(dd.getDate());
if (startObj.getValue() == null) {
startObj.setValue(instant);
}
endObj.setValue(instant);
if (instant.equals(interval.determineStart(instant))) {
final AggregationIntervalInfo intervalInfo = aggregationIntervalHelper.getIntervalInfo(interval, instant);
final T baseAggregationA = getAggregationDao().createAggregation(createAggregationKey(intervalInfo, groupA));
final T baseAggregationB = getAggregationDao().createAggregation(createAggregationKey(intervalInfo, groupB));
for (int u = 0; u < r.nextInt(50); u++) {
updateAggregation(intervalInfo, baseAggregationA, r);
updateAggregation(intervalInfo, baseAggregationB, r);
}
baseAggregationA.intervalComplete(5);
baseAggregationB.intervalComplete(5);
getAggregationDao().updateAggregation(baseAggregationA);
getAggregationDao().updateAggregation(baseAggregationB);
aggrs.add(2);
}
}
});
}
});
// Verify all aggrs created
assertEquals(1152, aggrs.intValue());
// Find aggrs for one day
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final AggregatedGroupMapping groupA = aggregatedGroupLookupDao.getGroupMapping("local.0");
final AggregatedGroupMapping groupB = aggregatedGroupLookupDao.getGroupMapping("local.1");
final DateTime queryStart = start.toDateMidnight().toDateTime();
final DateTime queryEnd = queryStart.plusDays(1).minusSeconds(1);
final List<T> baseAggregations = getAggregationDao().getAggregations(queryStart, queryEnd, createAggregationKey(interval, groupA), groupB);
assertEquals(158, baseAggregations.size());
}
});
// Find aggrs for second day
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final AggregatedGroupMapping groupA = aggregatedGroupLookupDao.getGroupMapping("local.0");
final AggregatedGroupMapping groupB = aggregatedGroupLookupDao.getGroupMapping("local.1");
final DateTime queryStart = start.toDateMidnight().minusDays(1).toDateTime();
final DateTime queryEnd = queryStart.plusDays(2).minusSeconds(1);
final List<T> baseAggregations = getAggregationDao().getAggregations(queryStart, queryEnd, createAggregationKey(interval, groupA), groupB);
assertEquals(158, baseAggregations.size());
}
});
// Find all aggrs
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final AggregatedGroupMapping groupA = aggregatedGroupLookupDao.getGroupMapping("local.0");
final AggregatedGroupMapping groupB = aggregatedGroupLookupDao.getGroupMapping("local.1");
final List<T> baseAggregations = getAggregationDao().getAggregations(start, end.plusDays(1), createAggregationKey(interval, groupA), groupB);
assertEquals(1152, baseAggregations.size());
}
});
// Find first days worth
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final AggregatedGroupMapping groupA = aggregatedGroupLookupDao.getGroupMapping("local.0");
final AggregatedGroupMapping groupB = aggregatedGroupLookupDao.getGroupMapping("local.1");
final List<T> baseAggregations = getAggregationDao().getAggregations(start, end, createAggregationKey(interval, groupA), groupB);
assertEquals(1152, baseAggregations.size());
}
});
// Find second days worth
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final AggregatedGroupMapping groupA = aggregatedGroupLookupDao.getGroupMapping("local.0");
final AggregatedGroupMapping groupB = aggregatedGroupLookupDao.getGroupMapping("local.1");
final List<T> baseAggregations = getAggregationDao().getAggregations(start.plusDays(1), end.plusDays(1), createAggregationKey(interval, groupA), groupB);
assertEquals(576, baseAggregations.size());
}
});
// Find first 12 hours worth
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final AggregatedGroupMapping groupA = aggregatedGroupLookupDao.getGroupMapping("local.0");
final AggregatedGroupMapping groupB = aggregatedGroupLookupDao.getGroupMapping("local.1");
final List<T> baseAggregations = getAggregationDao().getAggregations(start, start.plusHours(12), createAggregationKey(interval, groupA), groupB);
assertEquals(288, baseAggregations.size());
}
});
// Find middle 24 hours worth
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final AggregatedGroupMapping groupA = aggregatedGroupLookupDao.getGroupMapping("local.0");
final AggregatedGroupMapping groupB = aggregatedGroupLookupDao.getGroupMapping("local.1");
final List<T> baseAggregations = getAggregationDao().getAggregations(start.plusHours(12), end.plusHours(12), createAggregationKey(interval, groupA), groupB);
assertEquals(864, baseAggregations.size());
}
});
// Find middle 24 hours worth for one group
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final AggregatedGroupMapping groupA = aggregatedGroupLookupDao.getGroupMapping("local.0");
final List<T> baseAggregations = getAggregationDao().getAggregations(start.plusHours(12), end.plusHours(12), createAggregationKey(interval, groupA));
assertEquals(432, baseAggregations.size());
}
});
// Find last 12 hours worth
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final AggregatedGroupMapping groupA = aggregatedGroupLookupDao.getGroupMapping("local.0");
final AggregatedGroupMapping groupB = aggregatedGroupLookupDao.getGroupMapping("local.1");
final List<T> baseAggregations = getAggregationDao().getAggregations(start.plusHours(36), end.plusDays(1), createAggregationKey(interval, groupA), groupB);
assertEquals(288, baseAggregations.size());
}
});
// TODO Query for intervals that are stored
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final Set<AggregatedGroupMapping> aggregatedGroupMappings = getAggregationDao().getAggregatedGroupMappings();
assertEquals(2, aggregatedGroupMappings.size());
final Set<AggregationInterval> aggregationIntervals = getAggregationDao().getAggregationIntervals();
assertEquals(1, aggregationIntervals.size());
}
});
}
use of org.apereo.portal.concurrency.CallableWithoutResult in project uPortal by Jasig.
the class JpaBaseAggregationDaoTest method testModifyingClosedAggregationRangeQuery.
@Test
public final void testModifyingClosedAggregationRangeQuery() throws Exception {
final IEntityGroup entityGroupA = mock(IEntityGroup.class);
when(entityGroupA.getServiceName()).thenReturn(new CompositeName("local"));
when(entityGroupA.getName()).thenReturn("Group A");
when(compositeGroupService.findGroup("local.0")).thenReturn(entityGroupA);
final MutableInt aggrs = new MutableInt();
// Create 10 minutes of aggregations
final DateTime start = new DateTime(1326734644000l, DateTimeZone.UTC).minuteOfDay().roundFloorCopy();
final DateTime end = start.plusMinutes(10);
final AggregationInterval interval = AggregationInterval.FIVE_MINUTE;
final MutableObject startObj = new MutableObject();
final MutableObject endObj = new MutableObject();
this.executeInTransaction(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final Random r = new Random(0);
final AggregatedGroupMapping groupA = aggregatedGroupLookupDao.getGroupMapping("local.0");
populateDateTimeDimensions(start, end, new FunctionWithoutResult<Tuple<DateDimension, TimeDimension>>() {
@Override
protected void applyWithoutResult(Tuple<DateDimension, TimeDimension> input) {
final TimeDimension td = input.second;
final DateDimension dd = input.first;
final DateTime instant = td.getTime().toDateTime(dd.getDate());
if (startObj.getValue() == null) {
startObj.setValue(instant);
}
endObj.setValue(instant);
if (instant.equals(interval.determineStart(instant))) {
final AggregationIntervalInfo intervalInfo = aggregationIntervalHelper.getIntervalInfo(interval, instant);
final T baseAggregationA = getAggregationDao().createAggregation(createAggregationKey(intervalInfo, groupA));
for (int u = 0; u < r.nextInt(50); u++) {
updateAggregation(intervalInfo, baseAggregationA, r);
}
baseAggregationA.intervalComplete(5);
getAggregationDao().updateAggregation(baseAggregationA);
aggrs.add(1);
}
}
});
}
});
// Verify all aggrs created
assertEquals(2, aggrs.intValue());
// Find unclosed 1 aggr
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final Random r = new Random(0);
final AggregatedGroupMapping groupA = aggregatedGroupLookupDao.getGroupMapping("local.0");
final K key = createAggregationKey(interval, groupA);
final List<T> aggregations = getAggregationDao().getAggregations(start.minusDays(1), end.plusDays(1), key);
assertEquals(2, aggregations.size());
for (final T baseAggregationImpl : aggregations) {
final DateTime instant = baseAggregationImpl.getDateTime();
final AggregationIntervalInfo intervalInfo = aggregationIntervalHelper.getIntervalInfo(interval, instant);
updateAggregation(intervalInfo, baseAggregationImpl, r);
// TODO verify unchanged
}
}
});
}
Aggregations