List of usage examples for java.util Date from
public static Date from(Instant instant)
From source file:com.vmware.photon.controller.api.client.resource.TenantsRestApiTest.java
@Test public void testDeleteAsync() throws IOException, InterruptedException { final Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); TenantsApi tenantsApi = new TenantsRestApi(restClient); final CountDownLatch latch = new CountDownLatch(1); tenantsApi.deleteAsync("foo", new FutureCallback<Task>() { @Override//from w ww. ja v a 2 s . com public void onSuccess(@Nullable Task result) { assertEquals(result, responseTask); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }
From source file:org.apdplat.superword.system.AntiRobotFilter.java
public void init(FilterConfig config) throws ServletException { int initialDelay = 24 - LocalDateTime.now().getHour(); scheduledExecutorService.scheduleAtFixedRate(() -> { try {//w ww .j a va2 s. co m LOG.info("clear last day anti-robot counter"); LocalDateTime timePoint = LocalDateTime.now().minusDays(1); String date = SIMPLE_DATE_FORMAT .format(Date.from(timePoint.atZone(ZoneId.systemDefault()).toInstant())); Map<String, Integer> archive = new HashMap<String, Integer>(); Enumeration<String> keys = servletContext.getAttributeNames(); while (keys.hasMoreElements()) { String key = keys.nextElement(); if (key.startsWith("anti-robot-") && key.endsWith(date)) { archive.put(key, ((AtomicInteger) servletContext.getAttribute(key)).intValue()); } } archive.keySet().forEach(servletContext::removeAttribute); File path = new File(servletContext.getRealPath("/WEB-INF/data/anti-robot-archive/")); if (!path.exists()) { path.mkdirs(); } String file = path.getPath() + "/" + date + "__user_agent_invalid_count_" + invalidCount + ".txt"; Files.write(Paths.get(file), archive.entrySet().stream() .map(e -> e.getKey().replace("anti-robot-", "").replace("-", "\t") + "\t" + e.getValue()) .map(line -> { String[] attrs = line.split("\\s+"); String location = ""; if (attrs != null && attrs.length > 1) { String ip = attrs[1]; location = IPUtils.getIPLocation(ip).toString(); } return line + "\t" + location; }).collect(Collectors.toList())); invalidCount = 0; LOG.info("clear last day anti-robot counter finished: " + file); } catch (Exception e) { LOG.error("save anti-robot-archive failed", e); } }, initialDelay, 24, TimeUnit.HOURS); }
From source file:com.vmware.photon.controller.api.client.resource.VmApiTest.java
@Test public void testAddTagToVm() throws IOException { Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); VmApi vmApi = new VmApi(restClient); Task task = vmApi.addTagToVm("foo", new Tag("tagValue")); assertEquals(task, responseTask);/*from w w w . j a va 2 s.c o m*/ }
From source file:org.apache.solr.client.solrj.io.stream.eval.TemporalEvaluatorsTest.java
@Test public void testFunctionsLocalDateTime() throws Exception { LocalDateTime localDateTime = LocalDateTime.of(2017, 12, 5, 23, 59); Date aDate = Date.from(localDateTime.atZone(ZoneOffset.UTC).toInstant()); testFunction("year(a)", localDateTime, 2017); testFunction("month(a)", localDateTime, 12); testFunction("day(a)", localDateTime, 5); testFunction("hour(a)", localDateTime, 23); testFunction("minute(a)", localDateTime, 59); testFunction("epoch(a)", localDateTime, aDate.getTime()); }
From source file:com.thinkbiganalytics.nifi.v2.ingest.GetTableData.java
public static Date toDate(LocalDateTime dateTime) { return dateTime == null ? new Date(0L) : Date.from(dateTime.toInstant(ZoneOffset.UTC)); }
From source file:com.vmware.photon.controller.api.client.resource.VmRestApiTest.java
@Test public void testAddTagToVm() throws IOException { Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); VmApi vmApi = new VmRestApi(restClient); Task task = vmApi.addTagToVm("foo", new Tag("tagValue")); assertEquals(task, responseTask);/* w w w . ja v a2 s . co m*/ }
From source file:org.ng200.openolympus.ContestTest.java
public Contest createContestDirectly(Duration duration) throws Exception { return this.contestService.saveContest(new Contest(Date.from(Instant.now()), duration, "TestContest_" + ContestTest.id++, new HashSet<Task>(), false)); }
From source file:org.kie.server.integrationtests.prometheus.PrometheusIntegrationTest.java
@Test @Category(JEEOnly.class) // Executor in kie-server-integ-tests-all is using JMS for execution. Skipping test for non JEE containers as they don't have JMS. public void testPrometheusJobMetrics() throws Exception { int currentNumberOfCancelled = jobServicesClient .getRequestsByStatus(Collections.singletonList(STATUS.CANCELLED.toString()), 0, 1000).size(); int currentNumberOfDone = jobServicesClient .getRequestsByStatus(Collections.singletonList(STATUS.DONE.toString()), 0, 1000).size(); Instant tomorrow = Instant.now().plus(1, ChronoUnit.DAYS); JobRequestInstance jobRequestInstanceTomorrow = createJobRequestInstance(); jobRequestInstanceTomorrow.setScheduledDate(Date.from(tomorrow)); Long jobIdTomorrow = jobServicesClient.scheduleRequest(jobRequestInstanceTomorrow); jobServicesClient.cancelRequest(jobIdTomorrow); JobRequestInstance jobRequestInstanceNow = createJobRequestInstance(); Long jobIdNow = jobServicesClient.scheduleRequest(jobRequestInstanceNow); KieServerSynchronization.waitForJobToFinish(jobServicesClient, jobIdNow); assertThat(getMetrics()).contains(// ww w .j a v a 2 s . co m "kie_server_job_scheduled_total{container_id=\"\",command_name=\"" + PRINT_OUT_COMMAND + "\",}", "kie_server_job_cancelled_total{container_id=\"\",command_name=\"" + PRINT_OUT_COMMAND + "\",} " + (currentNumberOfCancelled + 1) // Uncomment when JBPM-8452 is resolved. // "kie_server_job_executed_total{container_id=\"\",failed=\"false\",command_name=\"" + PRINT_OUT_COMMAND + "\",} " + (currentNumberOfDone + 1), // "kie_server_job_running_total{container_id=\"\",command_name=\"" + PRINT_OUT_COMMAND + "\",}", // "kie_server_job_duration_seconds_count{container_id=\"\",command_name=\"" + PRINT_OUT_COMMAND + "\",}", // "kie_server_job_duration_seconds_sum{container_id=\"\",command_name=\"" + PRINT_OUT_COMMAND + "\",}" ); }
From source file:org.helioviewer.jhv.plugins.hekplugin.HEKPlugin.java
public void dateTimesChanged(int framecount) { LocalDateTime startDateTime;// w ww. ja v a 2 s . c o m startDateTime = Plugins.getStartDateTime(); LocalDateTime endDateTime = Plugins.getEndDateTime(); if (startDateTime != null && endDateTime != null) { Date start = Date.from(startDateTime.atZone(ZoneId.systemDefault()).toInstant()); Date end = Date.from(endDateTime.atZone(ZoneId.systemDefault()).toInstant()); Interval<Date> newInterval = new Interval<>(start, end); hekPluginPanel.setCurInterval(newInterval); } }
From source file:com.vmware.photon.controller.api.client.resource.ProjectApiTest.java
@Test public void testCreatePersistentDisk() throws IOException { Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); ProjectApi projectApi = new ProjectApi(restClient); Task task = projectApi.createDisk("foo", new DiskCreateSpec()); assertEquals(task, responseTask);// w ww .j av a 2 s.c o m }