Search in sources :

Example 96 with Date

use of java.util.Date in project hadoop by apache.

the class TestJobInfo method testGetFormattedStartTimeStr.

@Test
public void testGetFormattedStartTimeStr() {
    JobReport jobReport = mock(JobReport.class);
    when(jobReport.getStartTime()).thenReturn(-1L);
    Job job = mock(Job.class);
    when(job.getReport()).thenReturn(jobReport);
    when(job.getName()).thenReturn("TestJobInfo");
    when(job.getState()).thenReturn(JobState.SUCCEEDED);
    JobId jobId = MRBuilderUtils.newJobId(1L, 1, 1);
    when(job.getID()).thenReturn(jobId);
    DateFormat dateFormat = new SimpleDateFormat();
    JobInfo jobInfo = new JobInfo(job);
    Assert.assertEquals(JobInfo.NA, jobInfo.getFormattedStartTimeStr(dateFormat));
    Date date = new Date();
    when(jobReport.getStartTime()).thenReturn(date.getTime());
    jobInfo = new JobInfo(job);
    Assert.assertEquals(dateFormat.format(date), jobInfo.getFormattedStartTimeStr(dateFormat));
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) CompletedJob(org.apache.hadoop.mapreduce.v2.hs.CompletedJob) Job(org.apache.hadoop.mapreduce.v2.app.job.Job) SimpleDateFormat(java.text.SimpleDateFormat) JobId(org.apache.hadoop.mapreduce.v2.api.records.JobId) Date(java.util.Date) JobReport(org.apache.hadoop.mapreduce.v2.api.records.JobReport) Test(org.junit.Test)

Example 97 with Date

use of java.util.Date in project hadoop by apache.

the class SelfThrottlingIntercept method sendingRequest.

public void sendingRequest(SendingRequestEvent sendEvent) {
    long lastLatency;
    // for logging
    boolean operationIsRead;
    synchronized (this) {
        lastLatency = this.lastE2Elatency;
    }
    float sleepMultiple;
    HttpURLConnection urlConnection = (HttpURLConnection) sendEvent.getConnectionObject();
    // upload.
    if (urlConnection.getRequestMethod().equalsIgnoreCase("PUT")) {
        operationIsRead = false;
        sleepMultiple = (1 / writeFactor) - 1;
    } else {
        operationIsRead = true;
        sleepMultiple = (1 / readFactor) - 1;
    }
    long sleepDuration = (long) (sleepMultiple * lastLatency);
    if (sleepDuration < 0) {
        sleepDuration = 0;
    }
    if (sleepDuration > 0) {
        try {
            // Thread.sleep() is not exact but it seems sufficiently accurate for
            // our needs. If needed this could become a loop of small waits that
            // tracks actual
            // elapsed time.
            Thread.sleep(sleepDuration);
        } catch (InterruptedException ie) {
            Thread.currentThread().interrupt();
        }
        // reset to avoid counting the sleep against request latency
        sendEvent.getRequestResult().setStartDate(new Date());
    }
    if (LOG.isDebugEnabled()) {
        boolean isFirstRequest = (lastLatency == 0);
        long threadId = Thread.currentThread().getId();
        LOG.debug(String.format(" SelfThrottlingIntercept:: SendingRequest:   threadId=%d, requestType=%s, isFirstRequest=%b, sleepDuration=%d", threadId, operationIsRead ? "read " : "write", isFirstRequest, sleepDuration));
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) Date(java.util.Date)

Example 98 with Date

use of java.util.Date in project hadoop by apache.

the class SelfThrottlingIntercept method responseReceived.

public void responseReceived(ResponseReceivedEvent event) {
    RequestResult result = event.getRequestResult();
    Date startDate = result.getStartDate();
    Date stopDate = result.getStopDate();
    long elapsed = stopDate.getTime() - startDate.getTime();
    synchronized (this) {
        this.lastE2Elatency = elapsed;
    }
    if (LOG.isDebugEnabled()) {
        int statusCode = result.getStatusCode();
        String etag = result.getEtag();
        HttpURLConnection urlConnection = (HttpURLConnection) event.getConnectionObject();
        int contentLength = urlConnection.getContentLength();
        String requestMethod = urlConnection.getRequestMethod();
        long threadId = Thread.currentThread().getId();
        LOG.debug(String.format("SelfThrottlingIntercept:: ResponseReceived: threadId=%d, Status=%d, Elapsed(ms)=%d, ETAG=%s, contentLength=%d, requestMethod=%s", threadId, statusCode, elapsed, etag, contentLength, requestMethod));
    }
}
Also used : RequestResult(com.microsoft.azure.storage.RequestResult) HttpURLConnection(java.net.HttpURLConnection) Date(java.util.Date)

Example 99 with Date

use of java.util.Date in project hadoop by apache.

the class CustomMockTokenProvider method getExpiryTime.

@Override
public Date getExpiryTime() {
    Date before10Min = new Date();
    before10Min.setTime(expiryTime);
    return before10Min;
}
Also used : Date(java.util.Date)

Example 100 with Date

use of java.util.Date in project hadoop by apache.

the class NativeAzureFileSystemBaseTest method testModifiedTime.

private void testModifiedTime(Path testPath) throws Exception {
    Calendar utc = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    long currentUtcTime = utc.getTime().getTime();
    FileStatus fileStatus = fs.getFileStatus(testPath);
    // Give it +/-10 seconds
    final long errorMargin = 10 * 1000;
    assertTrue("Modification time " + new Date(fileStatus.getModificationTime()) + " is not close to now: " + utc.getTime(), fileStatus.getModificationTime() > (currentUtcTime - errorMargin) && fileStatus.getModificationTime() < (currentUtcTime + errorMargin));
}
Also used : FileStatus(org.apache.hadoop.fs.FileStatus) Calendar(java.util.Calendar) Date(java.util.Date)

Aggregations

Date (java.util.Date)11526 Test (org.junit.Test)2903 SimpleDateFormat (java.text.SimpleDateFormat)1601 ArrayList (java.util.ArrayList)1066 Calendar (java.util.Calendar)809 HashMap (java.util.HashMap)615 IOException (java.io.IOException)606 File (java.io.File)577 ParseException (java.text.ParseException)525 GregorianCalendar (java.util.GregorianCalendar)425 List (java.util.List)336 DateFormat (java.text.DateFormat)313 Map (java.util.Map)296 DateTime (org.joda.time.DateTime)239 Test (org.testng.annotations.Test)210 HashSet (java.util.HashSet)190 SQLException (java.sql.SQLException)167 LocalDate (org.joda.time.LocalDate)155 BigDecimal (java.math.BigDecimal)148 JSONObject (org.json.JSONObject)148