use of java.time.ZonedDateTime in project geode by apache.
the class ExportLogsStatsDUnitTest method startAndEndDateCanExcludeLogs.
@Test
public void startAndEndDateCanExcludeLogs() throws Exception {
connectIfNeeded();
ZonedDateTime now = LocalDateTime.now().atZone(ZoneId.systemDefault());
ZonedDateTime tomorrow = now.plusDays(1);
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(ONLY_DATE_FORMAT);
CommandStringBuilder commandStringBuilder = new CommandStringBuilder("export logs");
commandStringBuilder.addOption("start-time", dateTimeFormatter.format(tomorrow));
commandStringBuilder.addOption("log-level", "debug");
String output = connector.execute(commandStringBuilder.toString());
assertThat(output).contains("No files to be exported");
}
use of java.time.ZonedDateTime in project spring-framework by spring-projects.
the class DefaultEntityResponseBuilder method lastModified.
@Override
public EntityResponse.Builder<T> lastModified(ZonedDateTime lastModified) {
ZonedDateTime gmt = lastModified.withZoneSameInstant(ZoneId.of("GMT"));
String headerValue = DateTimeFormatter.RFC_1123_DATE_TIME.format(gmt);
this.headers.set(HttpHeaders.LAST_MODIFIED, headerValue);
return this;
}
use of java.time.ZonedDateTime in project presto by prestodb.
the class OrcTester method preprocessWriteValueOld.
private static Object preprocessWriteValueOld(TypeInfo typeInfo, Object value) {
if (value == null) {
return null;
}
switch(typeInfo.getCategory()) {
case PRIMITIVE:
PrimitiveObjectInspector.PrimitiveCategory primitiveCategory = ((PrimitiveTypeInfo) typeInfo).getPrimitiveCategory();
switch(primitiveCategory) {
case BOOLEAN:
return value;
case BYTE:
return ((Number) value).byteValue();
case SHORT:
return ((Number) value).shortValue();
case INT:
return ((Number) value).intValue();
case LONG:
return ((Number) value).longValue();
case FLOAT:
return ((Number) value).floatValue();
case DOUBLE:
return ((Number) value).doubleValue();
case DECIMAL:
return HiveDecimal.create(((SqlDecimal) value).toBigDecimal());
case STRING:
return value;
case CHAR:
return new HiveChar(value.toString(), ((CharTypeInfo) typeInfo).getLength());
case DATE:
int days = ((SqlDate) value).getDays();
LocalDate localDate = LocalDate.ofEpochDay(days);
ZonedDateTime zonedDateTime = localDate.atStartOfDay(ZoneId.systemDefault());
long millis = zonedDateTime.toEpochSecond() * 1000;
Date date = new Date(0);
// mills must be set separately to avoid masking
date.setTime(millis);
return date;
case TIMESTAMP:
long millisUtc = (int) ((SqlTimestamp) value).getMillisUtc();
return new Timestamp(millisUtc);
case BINARY:
return ((SqlVarbinary) value).getBytes();
}
break;
case MAP:
MapTypeInfo mapTypeInfo = (MapTypeInfo) typeInfo;
TypeInfo keyTypeInfo = mapTypeInfo.getMapKeyTypeInfo();
TypeInfo valueTypeInfo = mapTypeInfo.getMapValueTypeInfo();
Map<Object, Object> newMap = new HashMap<>();
for (Entry<?, ?> entry : ((Map<?, ?>) value).entrySet()) {
newMap.put(preprocessWriteValueOld(keyTypeInfo, entry.getKey()), preprocessWriteValueOld(valueTypeInfo, entry.getValue()));
}
return newMap;
case LIST:
ListTypeInfo listTypeInfo = (ListTypeInfo) typeInfo;
TypeInfo elementTypeInfo = listTypeInfo.getListElementTypeInfo();
List<Object> newList = new ArrayList<>(((Collection<?>) value).size());
for (Object element : (Iterable<?>) value) {
newList.add(preprocessWriteValueOld(elementTypeInfo, element));
}
return newList;
case STRUCT:
StructTypeInfo structTypeInfo = (StructTypeInfo) typeInfo;
List<?> fieldValues = (List<?>) value;
List<TypeInfo> fieldTypeInfos = structTypeInfo.getAllStructFieldTypeInfos();
List<Object> newStruct = new ArrayList<>();
for (int fieldId = 0; fieldId < fieldValues.size(); fieldId++) {
newStruct.add(preprocessWriteValueOld(fieldTypeInfos.get(fieldId), fieldValues.get(fieldId)));
}
return newStruct;
}
throw new PrestoException(NOT_SUPPORTED, format("Unsupported Hive type: %s", typeInfo));
}
use of java.time.ZonedDateTime in project caffeine by ben-manes.
the class WriteBehindCacheWriterTest method givenMultipleCacheUpdatesOnSameKey_writeBehindIsCalledWithMostRecentTime.
@Test
public void givenMultipleCacheUpdatesOnSameKey_writeBehindIsCalledWithMostRecentTime() {
AtomicBoolean writerCalled = new AtomicBoolean(false);
AtomicInteger numberOfEntries = new AtomicInteger(0);
AtomicReference<ZonedDateTime> timeInWriteBehind = new AtomicReference<>();
// Given this cache...
Cache<Long, ZonedDateTime> cache = Caffeine.newBuilder().writer(new WriteBehindCacheWriter.Builder<Long, ZonedDateTime>().bufferTime(1, TimeUnit.SECONDS).coalesce(BinaryOperator.maxBy(ZonedDateTime::compareTo)).writeAction(entries -> {
if (entries.isEmpty()) {
return;
}
numberOfEntries.set(entries.size());
ZonedDateTime zonedDateTime = entries.values().iterator().next();
timeInWriteBehind.set(zonedDateTime);
writerCalled.set(true);
}).build()).build();
// When these cache updates happen ...
cache.put(1L, ZonedDateTime.of(2016, 6, 26, 8, 0, 0, 0, ZoneId.systemDefault()));
cache.put(1L, ZonedDateTime.of(2016, 6, 26, 8, 0, 0, 100, ZoneId.systemDefault()));
cache.put(1L, ZonedDateTime.of(2016, 6, 26, 8, 0, 0, 300, ZoneId.systemDefault()));
ZonedDateTime mostRecentTime = ZonedDateTime.of(2016, 6, 26, 8, 0, 0, 500, ZoneId.systemDefault());
cache.put(1L, mostRecentTime);
// Then the write behind action gets 1 entry to write with the most recent time
Awaitility.await().untilTrue(writerCalled);
Assert.assertEquals(1, numberOfEntries.intValue());
Assert.assertEquals(mostRecentTime, timeInWriteBehind.get());
}
use of java.time.ZonedDateTime in project cas by apereo.
the class GoogleAccountsServiceResponseBuilder method constructSamlResponse.
/**
* Construct SAML response.
* <a href="http://bit.ly/1uI8Ggu">See this reference for more info.</a>
*
* @param service the service
* @return the SAML response
*/
protected String constructSamlResponse(final GoogleAccountsService service) {
final ZonedDateTime currentDateTime = ZonedDateTime.now(ZoneOffset.UTC);
final ZonedDateTime notBeforeIssueInstant = ZonedDateTime.parse("2003-04-17T00:46:02Z");
final RegisteredService registeredService = servicesManager.findServiceBy(service);
if (registeredService == null || !registeredService.getAccessStrategy().isServiceAccessAllowed()) {
throw new UnauthorizedServiceException(UnauthorizedServiceException.CODE_UNAUTHZ_SERVICE);
}
final String userId = registeredService.getUsernameAttributeProvider().resolveUsername(service.getPrincipal(), service);
final org.opensaml.saml.saml2.core.Response response = this.samlObjectBuilder.newResponse(this.samlObjectBuilder.generateSecureRandomId(), currentDateTime, service.getId(), service);
response.setStatus(this.samlObjectBuilder.newStatus(StatusCode.SUCCESS, null));
final String sessionIndex = '_' + String.valueOf(Math.abs(new SecureRandom().nextLong()));
final AuthnStatement authnStatement = this.samlObjectBuilder.newAuthnStatement(AuthnContext.PASSWORD_AUTHN_CTX, currentDateTime, sessionIndex);
final Assertion assertion = this.samlObjectBuilder.newAssertion(authnStatement, casServerPrefix, notBeforeIssueInstant, this.samlObjectBuilder.generateSecureRandomId());
final Conditions conditions = this.samlObjectBuilder.newConditions(notBeforeIssueInstant, currentDateTime.plusSeconds(this.skewAllowance), service.getId());
assertion.setConditions(conditions);
final Subject subject = this.samlObjectBuilder.newSubject(NameID.EMAIL, userId, service.getId(), currentDateTime.plusSeconds(this.skewAllowance), service.getRequestId());
assertion.setSubject(subject);
response.getAssertions().add(assertion);
final StringWriter writer = new StringWriter();
this.samlObjectBuilder.marshalSamlXmlObject(response, writer);
final String result = writer.toString();
LOGGER.debug("Generated Google SAML response: [{}]", result);
return result;
}
Aggregations