Search in sources :

Example 71 with TimeUnit

use of java.util.concurrent.TimeUnit in project geode by apache.

the class InternalDataSerializer method readTimeUnit.

/**
   * Reads a {@code TimeUnit} from a {@code DataInput}.
   *
   * @throws IOException A problem occurs while writing to {@code out}
   */
private static TimeUnit readTimeUnit(DataInput in) throws IOException {
    InternalDataSerializer.checkIn(in);
    byte type = in.readByte();
    TimeUnit unit;
    switch(type) {
        case TIME_UNIT_NANOSECONDS:
            unit = TimeUnit.NANOSECONDS;
            break;
        case TIME_UNIT_MICROSECONDS:
            unit = TimeUnit.MICROSECONDS;
            break;
        case TIME_UNIT_MILLISECONDS:
            unit = TimeUnit.MILLISECONDS;
            break;
        case TIME_UNIT_SECONDS:
            unit = TimeUnit.SECONDS;
            break;
        default:
            throw new IOException(LocalizedStrings.DataSerializer_UNKNOWN_TIMEUNIT_TYPE_0.toLocalizedString(type));
    }
    if (logger.isTraceEnabled(LogMarker.SERIALIZER)) {
        logger.trace(LogMarker.SERIALIZER, "Read TimeUnit: {}", unit);
    }
    return unit;
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) IOException(java.io.IOException) GemFireIOException(org.apache.geode.GemFireIOException)

Example 72 with TimeUnit

use of java.util.concurrent.TimeUnit in project geode by apache.

the class DataTypeJUnitTest method testTimeUnit.

@Test
public void testTimeUnit() throws IOException {
    final EnumSet<TimeUnit> optimizedTimeUnits = EnumSet.range(TimeUnit.NANOSECONDS, TimeUnit.SECONDS);
    for (TimeUnit v : TimeUnit.values()) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream out = new DataOutputStream(baos);
        DataSerializer.writeObject(v, out);
        byte[] bytes = baos.toByteArray();
        // 4?
        String type = DataType.getDataType(bytes);
        if (optimizedTimeUnits.contains(v)) {
            assertEquals("for enum " + v, "java.util.concurrent.TimeUnit", type);
        } else {
            assertEquals("for enum " + v, "java.lang.Enum:java.util.concurrent.TimeUnit", type);
        }
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) TimeUnit(java.util.concurrent.TimeUnit) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UnitTest(org.apache.geode.test.junit.categories.UnitTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 73 with TimeUnit

use of java.util.concurrent.TimeUnit in project geode by apache.

the class DataSerializableJUnitTest method testTimeUnitObject.

/**
   * Tests data serializing {@link TimeUnit}s using {@link DataSerializer#writeObject}.
   */
@Test
public void testTimeUnitObject() throws Exception {
    DataOutputStream out = getDataOutput();
    for (TimeUnit v : TimeUnit.values()) {
        DataSerializer.writeObject(v, out, false);
    }
    out.flush();
    DataInput in = getDataInput();
    for (TimeUnit v : TimeUnit.values()) {
        assertEquals(v, DataSerializer.readObject(in));
    }
}
Also used : DataInput(java.io.DataInput) DataOutputStream(java.io.DataOutputStream) TimeUnit(java.util.concurrent.TimeUnit) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 74 with TimeUnit

use of java.util.concurrent.TimeUnit in project geode by apache.

the class WaitUntilParallelGatewaySenderFlushedCoordinatorJUnitTest method testWaitUntilParallelGatewaySenderFlushedSuccessfulInitiator.

@Test
public void testWaitUntilParallelGatewaySenderFlushedSuccessfulInitiator() throws Throwable {
    long timeout = 5000;
    TimeUnit unit = TimeUnit.MILLISECONDS;
    WaitUntilParallelGatewaySenderFlushedCoordinator coordinator = new WaitUntilParallelGatewaySenderFlushedCoordinator(this.sender, timeout, unit, true);
    WaitUntilParallelGatewaySenderFlushedCoordinator coordinatorSpy = spy(coordinator);
    doReturn(getLocalBucketRegions()).when(coordinatorSpy).getLocalBucketRegions(any());
    doReturn(getCallableResult(true)).when(coordinatorSpy).createWaitUntilBucketRegionQueueFlushedCallable(any(), anyLong(), any());
    boolean result = coordinatorSpy.waitUntilFlushed();
    assertTrue(result);
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.Test) WaitUntilGatewaySenderFlushedCoordinatorJUnitTest(org.apache.geode.internal.cache.wan.WaitUntilGatewaySenderFlushedCoordinatorJUnitTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 75 with TimeUnit

use of java.util.concurrent.TimeUnit in project geode by apache.

the class WaitUntilParallelGatewaySenderFlushedCoordinatorJUnitTest method testWaitUntilParallelGatewaySenderFlushedSuccessfulNotInitiator.

@Test
public void testWaitUntilParallelGatewaySenderFlushedSuccessfulNotInitiator() throws Throwable {
    long timeout = 5000;
    TimeUnit unit = TimeUnit.MILLISECONDS;
    WaitUntilParallelGatewaySenderFlushedCoordinator coordinator = new WaitUntilParallelGatewaySenderFlushedCoordinator(this.sender, timeout, unit, false);
    WaitUntilParallelGatewaySenderFlushedCoordinator coordinatorSpy = spy(coordinator);
    doReturn(getLocalBucketRegions()).when(coordinatorSpy).getLocalBucketRegions(any());
    doReturn(getCallableResult(true)).when(coordinatorSpy).createWaitUntilBucketRegionQueueFlushedCallable(any(), anyLong(), any());
    boolean result = coordinatorSpy.waitUntilFlushed();
    assertTrue(result);
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.Test) WaitUntilGatewaySenderFlushedCoordinatorJUnitTest(org.apache.geode.internal.cache.wan.WaitUntilGatewaySenderFlushedCoordinatorJUnitTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

TimeUnit (java.util.concurrent.TimeUnit)190 Test (org.junit.Test)28 ExecutionException (java.util.concurrent.ExecutionException)16 IOException (java.io.IOException)11 TimeoutException (java.util.concurrent.TimeoutException)11 Future (java.util.concurrent.Future)10 HashMap (java.util.HashMap)7 TimeSpec (com.linkedin.thirdeye.api.TimeSpec)6 ArrayList (java.util.ArrayList)6 TimeValue (org.elasticsearch.common.unit.TimeValue)6 DataType (com.linkedin.pinot.common.data.FieldSpec.DataType)5 File (java.io.File)5 HashSet (java.util.HashSet)5 Matcher (java.util.regex.Matcher)5 WaitUntilGatewaySenderFlushedCoordinatorJUnitTest (org.apache.geode.internal.cache.wan.WaitUntilGatewaySenderFlushedCoordinatorJUnitTest)5 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)5 TimeGranularity (com.linkedin.thirdeye.api.TimeGranularity)4 GwtIncompatible (com.google.common.annotations.GwtIncompatible)3 RestException (com.linkedin.r2.message.rest.RestException)3 Map (java.util.Map)3