use of org.apache.beam.repackaged.core.org.apache.commons.lang3.mutable.MutableObject in project druid by druid-io.
the class VectorGroupByEngineIteratorTest method testCreateOneGrouperAndCloseItWhenClose.
@Test
public void testCreateOneGrouperAndCloseItWhenClose() throws IOException {
final Interval interval = TestIndex.DATA_INTERVAL;
final AggregatorFactory factory = new DoubleSumAggregatorFactory("index", "index");
final GroupByQuery query = GroupByQuery.builder().setDataSource(QueryRunnerTestHelper.DATA_SOURCE).setGranularity(QueryRunnerTestHelper.DAY_GRAN).setInterval(interval).setDimensions(new DefaultDimensionSpec("market", null, null)).setAggregatorSpecs(factory).build();
final StorageAdapter storageAdapter = new QueryableIndexStorageAdapter(TestIndex.getMMappedTestIndex());
final ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[4096]);
final VectorCursor cursor = storageAdapter.makeVectorCursor(Filters.toFilter(query.getDimFilter()), interval, query.getVirtualColumns(), false, QueryContexts.getVectorSize(query), null);
final List<GroupByVectorColumnSelector> dimensions = query.getDimensions().stream().map(dimensionSpec -> ColumnProcessors.makeVectorProcessor(dimensionSpec, GroupByVectorColumnProcessorFactory.instance(), cursor.getColumnSelectorFactory())).collect(Collectors.toList());
final MutableObject<VectorGrouper> grouperCaptor = new MutableObject<>();
final VectorGroupByEngineIterator iterator = new VectorGroupByEngineIterator(query, new GroupByQueryConfig(), storageAdapter, cursor, interval, dimensions, byteBuffer, null) {
@Override
VectorGrouper makeGrouper() {
grouperCaptor.setValue(Mockito.spy(super.makeGrouper()));
return grouperCaptor.getValue();
}
};
iterator.close();
Mockito.verify(grouperCaptor.getValue()).close();
}
use of org.apache.beam.repackaged.core.org.apache.commons.lang3.mutable.MutableObject in project AgriCraft by AgriCraft.
the class AgriClocheRecipe method getRecipeOutput.
@Override
public ItemStack getRecipeOutput() {
MutableObject<ItemStack> product = new MutableObject<>();
this.getSeed().getPlant().getAllPossibleProducts(stack -> {
if (product.getValue() == null) {
product.setValue(stack);
}
});
ItemStack result = product.getValue();
return result == null ? ItemStack.EMPTY : result;
}
use of org.apache.beam.repackaged.core.org.apache.commons.lang3.mutable.MutableObject in project hive by apache.
the class TestReflectionObjectInspectors method testObjectInspectorThreadSafety.
@Test
public void testObjectInspectorThreadSafety() throws InterruptedException {
// 5 workers to run getReflectionObjectInspector concurrently
final int workerCount = 5;
final ScheduledExecutorService executorService = Executors.newScheduledThreadPool(workerCount);
final MutableObject exception = new MutableObject();
Thread runner = new Thread(new Runnable() {
@Override
@SuppressWarnings("unchecked")
public void run() {
Future<ObjectInspector>[] results = (Future<ObjectInspector>[]) new Future[workerCount];
Pair<Type, ObjectInspectorFactory.ObjectInspectorOptions>[] types = (Pair<Type, ObjectInspectorFactory.ObjectInspectorOptions>[]) new Pair[] { Pair.of(Complex.class, ObjectInspectorFactory.ObjectInspectorOptions.THRIFT), Pair.of(MyStruct.class, ObjectInspectorFactory.ObjectInspectorOptions.JAVA) };
try {
for (int i = 0; i < 20; i++) {
// repeat 20 times
for (final Pair<Type, ObjectInspectorFactory.ObjectInspectorOptions> t : types) {
ObjectInspectorFactory.objectInspectorCache.asMap().clear();
for (int k = 0; k < workerCount; k++) {
results[k] = executorService.schedule(new Callable<ObjectInspector>() {
@Override
public ObjectInspector call() throws Exception {
return ObjectInspectorFactory.getReflectionObjectInspector(t.getLeft(), t.getRight());
}
}, 50, TimeUnit.MILLISECONDS);
}
ObjectInspector oi = results[0].get();
for (int k = 1; k < workerCount; k++) {
assertEquals(oi, results[k].get());
}
}
}
} catch (Throwable e) {
exception.setValue(e);
}
}
});
try {
runner.start();
// timeout in 5 minutes
long endTime = System.currentTimeMillis() + 300000;
while (runner.isAlive()) {
if (System.currentTimeMillis() > endTime) {
// Interrupt the runner thread
runner.interrupt();
fail("Timed out waiting for the runner to finish");
}
runner.join(10000);
}
if (exception.getValue() != null) {
fail("Got exception: " + exception.getValue());
}
} finally {
executorService.shutdownNow();
}
}
use of org.apache.beam.repackaged.core.org.apache.commons.lang3.mutable.MutableObject in project xm-ms-entity by xm-online.
the class XmEntityResourceExtendedIntTest method testAttachmentStartDate.
@Test
@Transactional
public void testAttachmentStartDate() throws Exception {
Attachment attachment = new Attachment().typeKey("A").name("1");
XmEntity entity = new XmEntity().name(" ").key(randomUUID()).typeKey("TEST_DELETE").attachments(asSet(attachment));
MutableObject<Instant> startDate = new MutableObject<>();
MutableObject<XmEntity> entityHolder = new MutableObject<>();
byte[] content = TestUtil.convertObjectToJsonBytes(entity);
restXmEntityMockMvc.perform(post("/api/xm-entities").contentType(TestUtil.APPLICATION_JSON_UTF8).content(content)).andDo(r -> entityHolder.setValue(readValue(r))).andDo(r -> log.info(r.getResponse().getContentAsString())).andExpect(status().is2xxSuccessful());
Long id = entityHolder.getValue().getId();
restXmEntityMockMvc.perform(get("/api/xm-entities/" + id)).andDo(r -> startDate.setValue(readValue(r).getAttachments().iterator().next().getStartDate())).andDo(r -> log.info(r.getResponse().getContentAsString())).andExpect(status().is2xxSuccessful());
assertNotNull(startDate.getValue());
content = TestUtil.convertObjectToJsonBytes(entityHolder.getValue());
restXmEntityMockMvc.perform(put("/api/xm-entities").contentType(TestUtil.APPLICATION_JSON_UTF8).content(content)).andDo(r -> log.info(r.getResponse().getContentAsString())).andExpect(status().is2xxSuccessful());
restXmEntityMockMvc.perform(get("/api/xm-entities/" + id)).andDo(r -> log.info(r.getResponse().getContentAsString())).andDo(r -> assertEquals(startDate.getValue(), readValue(r).getAttachments().iterator().next().getStartDate())).andExpect(status().is2xxSuccessful());
}
use of org.apache.beam.repackaged.core.org.apache.commons.lang3.mutable.MutableObject in project vcell by virtualcell.
the class Xmlproducer method getXML.
/**
* This method returns a XML representation of a MembraneSubDomain object.
* Creation date: (3/2/2001 5:40:17 PM)
* @return Element
* @param param cbit.vcell.math.MembraneSubDomain
*/
private Element getXML(MembraneSubDomain param) throws XmlParseException {
Element membrane = new Element(XMLTags.MembraneSubDomainTag);
// Add attributes
membrane.setAttribute(XMLTags.NameAttrTag, mangle(param.getName()));
membrane.setAttribute(XMLTags.InsideCompartmentTag, mangle(param.getInsideCompartment().getName()));
membrane.setAttribute(XMLTags.OutsideCompartmentTag, mangle(param.getOutsideCompartment().getName()));
// Add boundaryType subelements
Element boundary;
// Xm
boundary = new Element(XMLTags.BoundaryTypeTag);
boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueXm);
boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionXm().boundaryTypeStringValue());
membrane.addContent(boundary);
// Xp
boundary = new Element(XMLTags.BoundaryTypeTag);
boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueXp);
boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionXp().boundaryTypeStringValue());
membrane.addContent(boundary);
// Ym
boundary = new Element(XMLTags.BoundaryTypeTag);
boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueYm);
boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionYm().boundaryTypeStringValue());
membrane.addContent(boundary);
// Yp
boundary = new Element(XMLTags.BoundaryTypeTag);
boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueYp);
boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionYp().boundaryTypeStringValue());
membrane.addContent(boundary);
// Zm
boundary = new Element(XMLTags.BoundaryTypeTag);
boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueZm);
boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionZm().boundaryTypeStringValue());
membrane.addContent(boundary);
// Zp
boundary = new Element(XMLTags.BoundaryTypeTag);
boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueZp);
boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionZp().boundaryTypeStringValue());
membrane.addContent(boundary);
// Add Equation subelements
Enumeration<Equation> enum1 = param.getEquations();
while (enum1.hasMoreElements()) {
Equation equ = enum1.nextElement();
membrane.addContent(getXML(equ));
}
// Add JumConditions
Enumeration<JumpCondition> enum2 = param.getJumpConditions();
while (enum2.hasMoreElements()) {
JumpCondition jc = (JumpCondition) enum2.nextElement();
membrane.addContent(getXML(jc));
}
// Add FastSystem (if there is)
if (param.getFastSystem() != null) {
membrane.addContent(getXML(param.getFastSystem()));
}
for (ParticleProperties pp : param.getParticleProperties()) {
membrane.addContent(getXML(pp));
}
for (ParticleJumpProcess pjp : param.getParticleJumpProcesses()) {
membrane.addContent(getXML(pjp));
}
Mutable<Element> velocity = new MutableObject<>();
addVelocityMaybe(velocity, XMLTags.XAttrTag, param.getVelocityX());
addVelocityMaybe(velocity, XMLTags.YAttrTag, param.getVelocityY());
if (velocity.getValue() != null) {
membrane.addContent(velocity.getValue());
}
return membrane;
}
Aggregations