use of org.apache.commons.lang3.mutable.MutableInt in project sling by apache.
the class PollingTest method testNegativeTimeout.
@Test
public void testNegativeTimeout() throws Exception {
final MutableInt callCount = new MutableInt(0);
Polling p = new Polling() {
@Override
public Boolean call() throws Exception {
callCount.increment();
return true;
}
};
p.poll(-1, 10);
assertEquals(1, callCount.intValue());
}
use of org.apache.commons.lang3.mutable.MutableInt in project hive by apache.
the class SourceStateTracker method getFragmentRuntimeInfo.
// Assumes serialized DAGs within an AM, and a reset of structures after each DAG completes.
/**
* Constructs FragmentRuntimeInfo for scheduling within LLAP daemons.
* Also caches state based on state updates.
* @param vertexName
* @param fragmentNumber
* @param priority
* @return
*/
public synchronized FragmentRuntimeInfo getFragmentRuntimeInfo(String vertexName, int fragmentNumber, int priority) {
FragmentRuntimeInfo.Builder builder = FragmentRuntimeInfo.newBuilder();
maybeRegisterForVertexUpdates(vertexName);
MutableInt totalTaskCount = new MutableInt(0);
MutableInt completedTaskCount = new MutableInt(0);
computeUpstreamTaskCounts(completedTaskCount, totalTaskCount, vertexName);
builder.setNumSelfAndUpstreamCompletedTasks(completedTaskCount.intValue());
builder.setNumSelfAndUpstreamTasks(totalTaskCount.intValue());
builder.setDagStartTime(taskCommunicatorContext.getDagStartTime());
builder.setWithinDagPriority(priority);
builder.setFirstAttemptStartTime(taskCommunicatorContext.getFirstAttemptStartTime(vertexName, fragmentNumber));
builder.setCurrentAttemptStartTime(System.currentTimeMillis());
return builder.build();
}
use of org.apache.commons.lang3.mutable.MutableInt in project apex-malhar by apache.
the class AbstractFileOutputOperator method getPartFileNamePri.
/**
* Gets the current rolling file name.
* @param fileName The base name of the files you are rolling over.
* @return The name of the current rolling file.
*/
protected String getPartFileNamePri(String fileName) {
if (!rollingFile) {
return fileName;
}
MutableInt part = openPart.get(fileName);
if (part == null) {
part = new MutableInt(0);
openPart.put(fileName, part);
LOG.debug("First file part number {}", part);
}
return getPartFileName(fileName, part.intValue());
}
use of org.apache.commons.lang3.mutable.MutableInt in project apex-malhar by apache.
the class GPOUtilsTest method objectSerdeTest.
@Test
public void objectSerdeTest() {
Map<String, Type> fieldToTypeKey = Maps.newHashMap();
fieldToTypeKey.put("publisher", Type.STRING);
fieldToTypeKey.put("advertiser", Type.STRING);
FieldsDescriptor fdkey = new FieldsDescriptor(fieldToTypeKey);
Map<String, Type> fieldToTypeAgg = Maps.newHashMap();
fieldToTypeAgg.put("clicks", Type.LONG);
fieldToTypeAgg.put("impressions", Type.LONG);
FieldsDescriptor fdagg = new FieldsDescriptor(fieldToTypeAgg);
Map<String, Type> fieldToType = Maps.newHashMap();
fieldToType.put("fdkeys", Type.OBJECT);
fieldToType.put("fdvalues", Type.OBJECT);
fieldToType.put("keys", Type.OBJECT);
fieldToType.put("values", Type.OBJECT);
Map<String, Serde> fieldToSerde = Maps.newHashMap();
fieldToSerde.put("fdkeys", SerdeFieldsDescriptor.INSTANCE);
fieldToSerde.put("fdvalues", SerdeFieldsDescriptor.INSTANCE);
fieldToSerde.put("keys", SerdeListGPOMutable.INSTANCE);
fieldToSerde.put("values", SerdeListGPOMutable.INSTANCE);
FieldsDescriptor metaDataFD = new FieldsDescriptor(fieldToType, fieldToSerde, new PayloadFix());
GPOMutable gpo = new GPOMutable(metaDataFD);
GPOMutable key1 = new GPOMutable(fdkey);
key1.setField("publisher", "google");
key1.setField("advertiser", "safeway");
GPOMutable key2 = new GPOMutable(fdkey);
key2.setField("publisher", "twitter");
key2.setField("advertiser", "blockbuster");
GPOMutable agg1 = new GPOMutable(fdagg);
agg1.setField("clicks", 10L);
agg1.setField("impressions", 11L);
GPOMutable agg2 = new GPOMutable(fdagg);
agg2.setField("clicks", 5L);
agg2.setField("impressions", 4L);
List<GPOMutable> keys = Lists.newArrayList(key1, key2);
List<GPOMutable> aggs = Lists.newArrayList(agg1, agg2);
gpo.getFieldsObject()[0] = fdkey;
gpo.getFieldsObject()[1] = fdagg;
gpo.getFieldsObject()[2] = keys;
gpo.getFieldsObject()[3] = aggs;
GPOByteArrayList bal = new GPOByteArrayList();
byte[] serialized = GPOUtils.serialize(gpo, bal);
GPOMutable newGPO = GPOUtils.deserialize(metaDataFD, serialized, new MutableInt(0));
newGPO.setFieldDescriptor(metaDataFD);
Assert.assertEquals(gpo, newGPO);
Assert.assertArrayEquals(gpo.getFieldsObject(), newGPO.getFieldsObject());
}
use of org.apache.commons.lang3.mutable.MutableInt in project apex-malhar by apache.
the class SerdeListGPOMutableTest method testSerialization.
@Test
public void testSerialization() {
final Map<String, Type> fieldToType = Maps.newHashMap();
final String tboolean = "tboolean";
final Boolean tbooleanv = true;
final Boolean tbooleanv1 = true;
final String tchar = "tchar";
final Character tcharv = 'A';
final Character tcharv1 = 'b';
final String tstring = "tstring";
final String tstringv = "hello";
final String tstringv1 = "hello1";
final String tfloat = "tfloat";
final Float tfloatv = 1.0f;
final Float tfloatv1 = 2.0f;
final String tdouble = "tdouble";
final Double tdoublev = 2.0;
final Double tdoublev1 = 3.0;
final String tbyte = "tbyte";
final Byte tbytev = 50;
final Byte tbytev1 = 55;
final String tshort = "tshort";
final Short tshortv = 1000;
final Short tshortv1 = 1300;
final String tinteger = "tinteger";
final Integer tintegerv = 100000;
final Integer tintegerv1 = 133000;
final String tlong = "tlong";
final Long tlongv = 10000000000L;
final Long tlongv1 = 10044400000L;
fieldToType.put(tboolean, Type.BOOLEAN);
fieldToType.put(tchar, Type.CHAR);
fieldToType.put(tstring, Type.STRING);
fieldToType.put(tfloat, Type.FLOAT);
fieldToType.put(tdouble, Type.DOUBLE);
fieldToType.put(tbyte, Type.BYTE);
fieldToType.put(tshort, Type.SHORT);
fieldToType.put(tinteger, Type.INTEGER);
fieldToType.put(tlong, Type.LONG);
FieldsDescriptor fd = new FieldsDescriptor(fieldToType);
GPOMutable gpo = new GPOMutable(fd);
gpo.setFieldGeneric(tboolean, tbooleanv);
gpo.setFieldGeneric(tchar, tcharv);
gpo.setField(tstring, tstringv);
gpo.setFieldGeneric(tfloat, tfloatv);
gpo.setFieldGeneric(tdouble, tdoublev);
gpo.setFieldGeneric(tbyte, tbytev);
gpo.setFieldGeneric(tshort, tshortv);
gpo.setFieldGeneric(tinteger, tintegerv);
gpo.setFieldGeneric(tlong, tlongv);
GPOMutable gpo1 = new GPOMutable(fd);
gpo1.setFieldGeneric(tboolean, tbooleanv1);
gpo1.setFieldGeneric(tchar, tcharv1);
gpo1.setField(tstring, tstringv1);
gpo1.setFieldGeneric(tfloat, tfloatv1);
gpo1.setFieldGeneric(tdouble, tdoublev1);
gpo1.setFieldGeneric(tbyte, tbytev1);
gpo1.setFieldGeneric(tshort, tshortv1);
gpo1.setFieldGeneric(tinteger, tintegerv1);
gpo1.setFieldGeneric(tlong, tlongv1);
List<GPOMutable> mutables = Lists.newArrayList(gpo, gpo1);
byte[] bytes = SerdeListGPOMutable.INSTANCE.serializeObject(mutables);
MutableInt offset = new MutableInt(0);
@SuppressWarnings("unchecked") List<GPOMutable> newMutables = (List<GPOMutable>) SerdeListGPOMutable.INSTANCE.deserializeObject(bytes, offset);
Assert.assertEquals(mutables, newMutables);
Assert.assertEquals(bytes.length, offset.intValue());
}
Aggregations