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;
}
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);
}
}
}
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));
}
}
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);
}
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);
}
Aggregations