use of org.joda.time.Period in project azure-sdk-for-java by Azure.
the class ServiceBusOperationsTests method canCreateNamespaceThenCRUDOnQueue.
@Test
public void canCreateNamespaceThenCRUDOnQueue() {
Region region = Region.US_EAST;
Creatable<ResourceGroup> rgCreatable = resourceManager.resourceGroups().define(RG_NAME).withRegion(region);
String namespaceDNSLabel = generateRandomResourceName("jvsbns", 15);
ServiceBusNamespace namespace = serviceBusManager.namespaces().define(namespaceDNSLabel).withRegion(region).withNewResourceGroup(rgCreatable).withSku(NamespaceSku.PREMIUM_CAPACITY1).create();
Assert.assertNotNull(namespace);
Assert.assertNotNull(namespace.inner());
String queueName = generateRandomResourceName("queue1-", 15);
Queue queue = namespace.queues().define(queueName).create();
Assert.assertNotNull(queue);
Assert.assertNotNull(queue.inner());
Assert.assertNotNull(queue.name());
Assert.assertTrue(queue.name().equalsIgnoreCase(queueName));
// Default lock duration is 1 minute, assert TimeSpan("00:01:00") parsing
//
Assert.assertEquals("00:01:00", queue.inner().lockDuration());
Assert.assertEquals(60, queue.lockDurationInSeconds());
Period dupDetectionDuration = queue.duplicateMessageDetectionHistoryDuration();
Assert.assertNotNull(dupDetectionDuration);
Assert.assertEquals(10, dupDetectionDuration.getMinutes());
// Default message TTL is TimeSpan.Max, assert parsing
//
Assert.assertEquals("10675199.02:48:05.4775807", queue.inner().defaultMessageTimeToLive());
Period msgTtlDuration = queue.defaultMessageTtlDuration();
Assert.assertNotNull(msgTtlDuration);
// Assert the default ttl TimeSpan("10675199.02:48:05.4775807") parsing
//
Assert.assertEquals(10675199, msgTtlDuration.getDays());
Assert.assertEquals(2, msgTtlDuration.getHours());
Assert.assertEquals(48, msgTtlDuration.getMinutes());
// Assert the default max size In MB
//
Assert.assertEquals(1024, queue.maxSizeInMB());
PagedList<Queue> queuesInNamespace = namespace.queues().list();
Assert.assertNotNull(queuesInNamespace);
Assert.assertTrue(queuesInNamespace.size() > 0);
Queue foundQueue = null;
for (Queue q : queuesInNamespace) {
if (q.name().equalsIgnoreCase(queueName)) {
foundQueue = q;
break;
}
}
Assert.assertNotNull(foundQueue);
// Dead lettering disabled by default
//
Assert.assertFalse(foundQueue.isDeadLetteringEnabledForExpiredMessages());
foundQueue = foundQueue.update().withMessageLockDurationInSeconds(120).withDefaultMessageTTL(new Period().withMinutes(20)).withExpiredMessageMovedToDeadLetterQueue().withMessageMovedToDeadLetterQueueOnMaxDeliveryCount(25).apply();
Assert.assertEquals(120, foundQueue.lockDurationInSeconds());
Assert.assertTrue(foundQueue.isDeadLetteringEnabledForExpiredMessages());
Assert.assertEquals(25, foundQueue.maxDeliveryCountBeforeDeadLetteringMessage());
namespace.queues().deleteByName(foundQueue.name());
}
use of org.joda.time.Period in project Activiti by Activiti.
the class TaskDueDateExtensionsTest method testRelativeDueDateStringExtension.
@Deployment
public void testRelativeDueDateStringExtension() throws Exception {
Clock clock = processEngineConfiguration.getClock();
clock.setCurrentCalendar(new GregorianCalendar(2015, 0, 1));
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("dateVariable", "P2DT5H40M");
// Start process-instance, passing ISO8601 duration formatted String that should be used to calculate dueDate
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("dueDateExtension", variables);
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(task.getDueDate());
Period period = new Period(task.getCreateTime().getTime(), task.getDueDate().getTime());
assertEquals(2, period.getDays());
assertEquals(5, period.getHours());
assertEquals(40, period.getMinutes());
clock.reset();
}
use of org.joda.time.Period in project graylog2-server by Graylog2.
the class TimeBasedRotationStrategyTest method shouldRotateNonIntegralPeriod.
@Test
public void shouldRotateNonIntegralPeriod() throws Exception {
// start 5 minutes before full hour
final DateTime initialTime = new DateTime(2014, 1, 1, 1, 55, 0, 0, DateTimeZone.UTC);
final Period period = minutes(10);
final InstantMillisProvider clock = new InstantMillisProvider(initialTime);
DateTimeUtils.setCurrentMillisProvider(clock);
when(indexSet.getConfig()).thenReturn(indexSetConfig);
when(indexSetConfig.rotationStrategy()).thenReturn(TimeBasedRotationStrategyConfig.create(period));
when(indices.indexCreationDate(anyString())).thenReturn(initialTime.minus(minutes(11)));
// Should rotate the first index.
// time is 01:55:00, index was created at 01:44:00, so we missed one period, and should rotate
when(indexSet.getNewestIndex()).thenReturn("ignored");
when(indexSet.getConfig()).thenReturn(indexSetConfig);
when(indexSetConfig.rotationStrategy()).thenReturn(TimeBasedRotationStrategyConfig.create(period));
rotationStrategy.rotate(indexSet);
verify(indexSet, times(1)).cycle();
reset(indexSet);
// advance time to 01:55:01
clock.tick(seconds(1));
// Did not cross rotation period.
when(indexSet.getNewestIndex()).thenReturn("ignored");
when(indexSet.getConfig()).thenReturn(indexSetConfig);
when(indexSetConfig.rotationStrategy()).thenReturn(TimeBasedRotationStrategyConfig.create(period));
rotationStrategy.rotate(indexSet);
verify(indexSet, never()).cycle();
reset(indexSet);
// advance time to 02:00:00
clock.tick(minutes(4).withSeconds(59));
// Crossed rotation period.
when(indexSet.getNewestIndex()).thenReturn("ignored");
when(indexSet.getConfig()).thenReturn(indexSetConfig);
when(indexSetConfig.rotationStrategy()).thenReturn(TimeBasedRotationStrategyConfig.create(period));
rotationStrategy.rotate(indexSet);
verify(indexSet, times(1)).cycle();
reset(indexSet);
// advance time multiple rotation periods into the future
// to time 02:51:00
clock.tick(minutes(51));
// Crossed multiple rotation periods.
when(indexSet.getNewestIndex()).thenReturn("ignored");
when(indexSet.getConfig()).thenReturn(indexSetConfig);
when(indexSetConfig.rotationStrategy()).thenReturn(TimeBasedRotationStrategyConfig.create(period));
rotationStrategy.rotate(indexSet);
verify(indexSet, times(1)).cycle();
reset(indexSet);
// move time to 2:52:00
// this should not cycle again, because next valid rotation time is 3:00:00
clock.tick(minutes(1));
when(indexSet.getNewestIndex()).thenReturn("ignored");
when(indexSet.getConfig()).thenReturn(indexSetConfig);
when(indexSetConfig.rotationStrategy()).thenReturn(TimeBasedRotationStrategyConfig.create(period));
rotationStrategy.rotate(indexSet);
verify(indexSet, never()).cycle();
reset(indexSet);
}
use of org.joda.time.Period in project graylog2-server by Graylog2.
the class TimeBasedRotationStrategyTest method shouldRotateHourly.
@Test
public void shouldRotateHourly() throws Exception {
final DateTime initialTime = new DateTime(2014, 1, 1, 1, 59, 59, 0, DateTimeZone.UTC);
final Period period = Period.hours(1);
final InstantMillisProvider clock = new InstantMillisProvider(initialTime);
DateTimeUtils.setCurrentMillisProvider(clock);
when(indexSet.getConfig()).thenReturn(indexSetConfig);
when(indexSetConfig.rotationStrategy()).thenReturn(TimeBasedRotationStrategyConfig.create(period));
when(indices.indexCreationDate(anyString())).thenReturn(initialTime.minus(minutes(5)));
// Should not rotate the first index.
when(indexSet.getNewestIndex()).thenReturn("ignored");
rotationStrategy.rotate(indexSet);
verify(indexSet, never()).cycle();
reset(indexSet);
clock.tick(seconds(2));
// Crossed rotation period.
when(indexSet.getNewestIndex()).thenReturn("ignored");
when(indexSet.getConfig()).thenReturn(indexSetConfig);
when(indexSetConfig.rotationStrategy()).thenReturn(TimeBasedRotationStrategyConfig.create(period));
rotationStrategy.rotate(indexSet);
verify(indexSet, times(1)).cycle();
reset(indexSet);
clock.tick(seconds(2));
// Did not cross rotation period.
when(indexSet.getNewestIndex()).thenReturn("ignored");
when(indexSet.getConfig()).thenReturn(indexSetConfig);
when(indexSetConfig.rotationStrategy()).thenReturn(TimeBasedRotationStrategyConfig.create(period));
rotationStrategy.rotate(indexSet);
verify(indexSet, never()).cycle();
reset(indexSet);
}
use of org.joda.time.Period in project graylog2-server by Graylog2.
the class TimeBasedRotationStrategy method shouldRotate.
@Nullable
@Override
protected Result shouldRotate(String index, IndexSet indexSet) {
final IndexSetConfig indexSetConfig = requireNonNull(indexSet.getConfig(), "Index set configuration must not be null");
final String indexSetId = indexSetConfig.id();
checkState(!isNullOrEmpty(index), "Index name must not be null or empty");
checkState(!isNullOrEmpty(indexSetId), "Index set ID must not be null or empty");
checkState(indexSetConfig.rotationStrategy() instanceof TimeBasedRotationStrategyConfig, "Invalid rotation strategy config <" + indexSetConfig.rotationStrategy().getClass().getCanonicalName() + "> for index set <" + indexSetId + ">");
final TimeBasedRotationStrategyConfig config = (TimeBasedRotationStrategyConfig) indexSetConfig.rotationStrategy();
final Period rotationPeriod = config.rotationPeriod().normalizedStandard();
final DateTime now = Tools.nowUTC();
// when first started, we might not know the last rotation time, look up the creation time of the index instead.
if (!lastRotation.containsKey(indexSetId)) {
final DateTime creationDate = indices.indexCreationDate(index);
if (creationDate != null) {
final DateTime currentAnchor = determineRotationPeriodAnchor(creationDate, rotationPeriod);
anchor.put(indexSetId, currentAnchor);
lastRotation.put(indexSetId, creationDate);
}
// still not able to figure out the last rotation time, we'll rotate forcibly
if (!lastRotation.containsKey(indexSetId)) {
return new SimpleResult(true, "No known previous rotation time, forcing index rotation now.");
}
}
final DateTime currentAnchor = anchor.get(indexSetId);
final DateTime nextRotation = currentAnchor.plus(rotationPeriod);
if (nextRotation.isAfter(now)) {
final String message = new MessageFormat("Next rotation at {0}", Locale.ENGLISH).format(new Object[] { nextRotation });
return new SimpleResult(false, message);
}
// determine new anchor (push it to within less then one period before now) in case we missed one or more periods
DateTime tmpAnchor;
int multiplicator = 0;
do {
tmpAnchor = currentAnchor.withPeriodAdded(rotationPeriod, ++multiplicator);
} while (tmpAnchor.isBefore(now));
final DateTime nextAnchor = currentAnchor.withPeriodAdded(rotationPeriod, multiplicator - 1);
anchor.put(indexSetId, nextAnchor);
lastRotation.put(indexSetId, now);
final String message = new MessageFormat("Rotation period {0} elapsed, next rotation at {1}", Locale.ENGLISH).format(new Object[] { now, nextAnchor });
return new SimpleResult(true, message);
}
Aggregations