Search in sources :

Example 1 with DateFormat

use of java.text.DateFormat in project hadoop by apache.

the class TestKeyProvider method testMetadata.

@Test
public void testMetadata() throws Exception {
    //Metadata without description
    DateFormat format = new SimpleDateFormat("y/m/d");
    Date date = format.parse("2013/12/25");
    KeyProvider.Metadata meta = new KeyProvider.Metadata("myCipher", 100, null, null, date, 123);
    assertEquals("myCipher", meta.getCipher());
    assertEquals(100, meta.getBitLength());
    assertNull(meta.getDescription());
    assertEquals(date, meta.getCreated());
    assertEquals(123, meta.getVersions());
    KeyProvider.Metadata second = new KeyProvider.Metadata(meta.serialize());
    assertEquals(meta.getCipher(), second.getCipher());
    assertEquals(meta.getBitLength(), second.getBitLength());
    assertNull(second.getDescription());
    assertTrue(second.getAttributes().isEmpty());
    assertEquals(meta.getCreated(), second.getCreated());
    assertEquals(meta.getVersions(), second.getVersions());
    int newVersion = second.addVersion();
    assertEquals(123, newVersion);
    assertEquals(124, second.getVersions());
    assertEquals(123, meta.getVersions());
    //Metadata with description
    format = new SimpleDateFormat("y/m/d");
    date = format.parse("2013/12/25");
    Map<String, String> attributes = new HashMap<String, String>();
    attributes.put("a", "A");
    meta = new KeyProvider.Metadata("myCipher", 100, "description", attributes, date, 123);
    assertEquals("myCipher", meta.getCipher());
    assertEquals(100, meta.getBitLength());
    assertEquals("description", meta.getDescription());
    assertEquals(attributes, meta.getAttributes());
    assertEquals(date, meta.getCreated());
    assertEquals(123, meta.getVersions());
    second = new KeyProvider.Metadata(meta.serialize());
    assertEquals(meta.getCipher(), second.getCipher());
    assertEquals(meta.getBitLength(), second.getBitLength());
    assertEquals(meta.getDescription(), second.getDescription());
    assertEquals(meta.getAttributes(), second.getAttributes());
    assertEquals(meta.getCreated(), second.getCreated());
    assertEquals(meta.getVersions(), second.getVersions());
    newVersion = second.addVersion();
    assertEquals(123, newVersion);
    assertEquals(124, second.getVersions());
    assertEquals(123, meta.getVersions());
}
Also used : HashMap(java.util.HashMap) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test)

Example 2 with DateFormat

use of java.text.DateFormat in project hadoop by apache.

the class TimedOutTestsListener method buildThreadDiagnosticString.

public static String buildThreadDiagnosticString() {
    StringWriter sw = new StringWriter();
    PrintWriter output = new PrintWriter(sw);
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss,SSS");
    output.println(String.format("Timestamp: %s", dateFormat.format(new Date())));
    output.println();
    output.println(buildThreadDump());
    String deadlocksInfo = buildDeadlockInfo();
    if (deadlocksInfo != null) {
        output.println("====> DEADLOCKS DETECTED <====");
        output.println();
        output.println(deadlocksInfo);
    }
    return sw.toString();
}
Also used : StringWriter(java.io.StringWriter) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) PrintWriter(java.io.PrintWriter)

Example 3 with DateFormat

use of java.text.DateFormat in project hadoop by apache.

the class VersionInfoMojo method getBuildTime.

/**
   * Returns a string representing current build time.
   * 
   * @return String representing current build time
   */
private String getBuildTime() {
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
    dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    return dateFormat.format(new Date());
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 4 with DateFormat

use of java.text.DateFormat in project hadoop by apache.

the class StatePool method initialize.

/**
   * Initialized the {@link StatePool}. This API also reloads the previously
   * persisted state. Note that the {@link StatePool} should be initialized only
   * once.
   */
public void initialize(Configuration conf) throws Exception {
    if (isInitialized) {
        throw new RuntimeException("StatePool is already initialized!");
    }
    this.conf = conf;
    String persistDir = conf.get(DIR_CONFIG);
    reload = conf.getBoolean(RELOAD_CONFIG, false);
    persist = conf.getBoolean(PERSIST_CONFIG, false);
    // reload if configured
    if (reload || persist) {
        System.out.println("State Manager initializing. State directory : " + persistDir);
        System.out.println("Reload:" + reload + " Persist:" + persist);
        if (persistDir == null) {
            throw new RuntimeException("No state persist directory configured!" + " Disable persistence.");
        } else {
            this.persistDirPath = new Path(persistDir);
        }
    } else {
        System.out.println("State Manager disabled.");
    }
    // reload
    reload();
    // now set the timestamp
    DateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy-hh'H'-mm'M'-ss'S'");
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    timeStamp = formatter.format(calendar.getTime());
    isInitialized = true;
}
Also used : Path(org.apache.hadoop.fs.Path) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) Calendar(java.util.Calendar) SimpleDateFormat(java.text.SimpleDateFormat)

Example 5 with DateFormat

use of java.text.DateFormat 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)

Aggregations

DateFormat (java.text.DateFormat)646 SimpleDateFormat (java.text.SimpleDateFormat)486 Date (java.util.Date)315 ParseException (java.text.ParseException)132 Calendar (java.util.Calendar)78 Test (org.junit.Test)69 ArrayList (java.util.ArrayList)48 IOException (java.io.IOException)43 File (java.io.File)31 HashMap (java.util.HashMap)27 GregorianCalendar (java.util.GregorianCalendar)24 TimeZone (java.util.TimeZone)23 Locale (java.util.Locale)18 Timestamp (java.sql.Timestamp)17 List (java.util.List)14 InputStream (java.io.InputStream)12 DateTime (org.joda.time.DateTime)11 Map (java.util.Map)10 Matcher (java.util.regex.Matcher)8 TestBean (org.springframework.tests.sample.beans.TestBean)8