use of java.time.ZonedDateTime in project sonarlint-core by SonarSource.
the class NotificationTimerTask method requestForServer.
private void requestForServer(ServerConfiguration serverConfiguration, List<NotificationConfiguration> configs) {
try {
Map<String, ZonedDateTime> request = configs.stream().collect(Collectors.toMap(NotificationConfiguration::projectKey, NotificationTimerTask::getLastNotificationTime, MERGE_TIMES));
NotificationChecker notificationChecker = checkerFactory.create(serverConfiguration);
List<SonarQubeNotification> notifications = notificationChecker.request(request);
for (SonarQubeNotification n : notifications) {
Stream<NotificationConfiguration> matchingConfStream = configs.stream();
if (n.projectKey() != null) {
matchingConfStream = matchingConfStream.filter(c -> c.projectKey().equals(n.projectKey()));
}
matchingConfStream.forEach(c -> {
c.listener().handle(n);
c.lastNotificationTime().set(n.time());
});
}
} catch (Exception e) {
LOG.warn("Failed to request SonarQube events to " + serverConfiguration.getUrl(), e);
}
}
use of java.time.ZonedDateTime in project sonarlint-core by SonarSource.
the class NotificationCheckerTest method testFailCode.
@Test
public void testFailCode() {
ZonedDateTime timestamp = ZonedDateTime.of(2017, 06, 04, 20, 0, 0, 0, ZoneOffset.ofHours(0));
String expectedUrl = "api/developers/search_events?projects=myproject&from=2017-06-04T20%3A00%3A00%2B0000";
SonarLintWsClient client = WsClientTestUtils.createMock();
WsClientTestUtils.addFailedResponse(client, expectedUrl, 404, "failed");
NotificationChecker checker = new NotificationChecker(client);
List<SonarQubeNotification> notifications = checker.request(Collections.singletonMap("myproject", timestamp));
assertThat(notifications).isEmpty();
}
use of java.time.ZonedDateTime in project sonarlint-core by SonarSource.
the class NotificationCheckerTest method testFailParsing.
@Test
public void testFailParsing() {
ZonedDateTime timestamp = ZonedDateTime.of(2017, 06, 04, 20, 0, 0, 0, ZoneOffset.ofHours(0));
String expectedUrl = "api/developers/search_events?projects=myproject&from=2017-06-04T20%3A00%3A00%2B0000";
SonarLintWsClient client = WsClientTestUtils.createMockWithResponse(expectedUrl, INVALID_RESPONSE);
NotificationChecker checker = new NotificationChecker(client);
List<SonarQubeNotification> notifications = checker.request(Collections.singletonMap("myproject", timestamp));
assertThat(notifications).isEmpty();
}
use of java.time.ZonedDateTime in project questdb by bluestreak01.
the class TimeZoneRulesImplTest method testCompatibility.
@Test
public void testCompatibility() {
Set<String> allZones = ZoneId.getAvailableZoneIds();
List<String> zoneList = new ArrayList<>(allZones);
Collections.sort(zoneList);
List<ZoneId> zones = new ArrayList<>(zoneList.size());
List<TimeZoneRulesImpl> zoneRules = new ArrayList<>(zoneList.size());
for (String z : zoneList) {
ZoneId zone = ZoneId.of(z);
zones.add(zone);
zoneRules.add(new TimeZoneRulesImpl(z, zone.getRules()));
}
long micros = Dates.toMicros(1900, 1, 1, 0, 0);
long deadline = Dates.toMicros(2115, 12, 31, 0, 0);
while (micros < deadline) {
int y = Dates.getYear(micros);
boolean leap = Dates.isLeapYear(y);
int m = Dates.getMonthOfYear(micros, y, leap);
int d = Dates.getDayOfMonth(micros, y, m, leap);
LocalDateTime dt = LocalDateTime.of(y, m, d, 0, 0);
for (int i = 0, n = zones.size(); i < n; i++) {
ZoneId zone = zones.get(i);
TimeZoneRulesImpl rules = zoneRules.get(i);
ZonedDateTime zdt = dt.atZone(zone);
long expected = zdt.getOffset().getTotalSeconds();
// find out how much algo added to datetime itself
long changed = Dates.toMicros(zdt.getYear(), zdt.getMonthValue(), zdt.getDayOfMonth(), zdt.getHour(), zdt.getMinute()) + zdt.getSecond() * Dates.SECOND_MICROS;
// add any extra time
expected += (changed - micros) / Dates.SECOND_MICROS;
long offset = rules.getOffset(micros, y, leap);
try {
Assert.assertEquals(expected, offset / Dates.SECOND_MICROS);
} catch (Throwable e) {
System.out.println(zone.getId() + "; " + zdt + "; " + Dates.toString(micros + offset));
System.out.println("e: " + expected + "; a: " + offset);
System.out.println(dt);
System.out.println(Dates.toString(micros));
throw e;
}
}
micros += Dates.DAY_MICROS;
}
}
use of java.time.ZonedDateTime in project questdb by bluestreak01.
the class TimeZoneRulesImplTest method testSingle.
@Test
public void testSingle() {
ZoneId zone = ZoneId.of("GMT");
TimeZoneRulesImpl rules = new TimeZoneRulesImpl("GMT", zone.getRules());
int y = 2017;
int m = 3;
int d = 29;
LocalDateTime dt = LocalDateTime.of(y, m, d, 0, 0);
long millis = Dates.toMicros(y, m, d, 0, 0);
ZonedDateTime zdt = dt.atZone(zone);
long expected = zdt.getOffset().getTotalSeconds();
// find out how much algo added to datetime itself
long changed = Dates.toMicros(zdt.getYear(), zdt.getMonthValue(), zdt.getDayOfMonth(), zdt.getHour(), zdt.getMinute()) + zdt.getSecond() * 1000;
// add any extra time
expected += (changed - millis) / 1000;
long offset = rules.getOffset(millis, y, Dates.isLeapYear(y));
try {
Assert.assertEquals(expected, offset / 1000);
} catch (Throwable e) {
System.out.println(zone.getId() + "; " + zdt + "; " + Dates.toString(millis + offset));
throw e;
}
}
Aggregations