use of java.util.concurrent.CopyOnWriteArraySet in project neo4j by neo4j.
the class ParallelInputEntityDeserializerTest method shouldParseDataInParallel.
@Test
public void shouldParseDataInParallel() throws Exception {
// GIVEN
int entities = 500;
Data<InputNode> data = testData(entities);
Configuration config = new Configuration.Overridden(COMMAS) {
@Override
public int bufferSize() {
return 100;
}
};
IdType idType = ACTUAL;
Collector badCollector = mock(Collector.class);
Groups groups = new Groups();
Set<Thread> observedProcessingThreads = new CopyOnWriteArraySet<>();
int threads = 4;
DeserializerFactory<InputNode> deserializerFactory = (header, chunk, decorator, validator) -> {
observedProcessingThreads.add(Thread.currentThread());
// Make sure there will be 4 different processing threads doing this
boolean allThreadsStarted;
do {
allThreadsStarted = observedProcessingThreads.size() == threads;
} while (!allThreadsStarted);
return new InputEntityDeserializer<>(header, chunk, config.delimiter(), new InputNodeDeserialization(header, chunk, groups, idType.idsAreExternal()), decorator, validator, badCollector);
};
try (ParallelInputEntityDeserializer<InputNode> deserializer = new ParallelInputEntityDeserializer<>(data, defaultFormatNodeFileHeader(), config, idType, threads, threads, deserializerFactory, Validators.<InputNode>emptyValidator(), InputNode.class)) {
// WHEN/THEN
long previousLineNumber = -1;
long previousPosition = -1;
for (long i = 0; i < entities; i++) {
assertTrue(deserializer.hasNext());
InputNode entity = deserializer.next();
assertEquals(i, ((Long) entity.id()).longValue());
assertEquals("name", entity.properties()[0]);
assertTrue(entity.properties()[1].toString().startsWith(i + "-"));
assertTrue(entity.lineNumber() > previousLineNumber);
previousLineNumber = entity.lineNumber();
assertTrue(entity.position() > previousPosition);
previousPosition = entity.position();
}
assertFalse(deserializer.hasNext());
assertEquals(threads, observedProcessingThreads.size());
}
}
use of java.util.concurrent.CopyOnWriteArraySet in project deltaspike by apache.
the class ViewConfigTest method testCallbackExecutionFolder.
@Test
public void testCallbackExecutionFolder() {
this.viewConfigExtension.addPageDefinition(Pages.class);
this.viewConfigExtension.addPageDefinition(Pages.Secure.class);
final SimpleTestAccessDecisionVoter1 testInstance1 = new SimpleTestAccessDecisionVoter1();
ViewConfigNode node = this.viewConfigExtension.findNode(Pages.Secure.class);
//add it to avoid in-container test for this simple constellation - usually not needed!
node.getCallbackDescriptors().put(TestSecured.class, new ArrayList<CallbackDescriptor>() {
{
add(new TestSecured.Descriptor(new Class[] { SimpleTestAccessDecisionVoter1.class }, DefaultCallback.class) {
@Override
protected Object getTargetObject(Class targetType) {
return testInstance1;
}
});
}
});
ViewConfigResolver viewConfigResolver = this.viewConfigResolverProducer.createViewConfigResolver();
ConfigDescriptor configDescriptor = viewConfigResolver.getConfigDescriptor(Pages.Secure.class);
Assert.assertNotNull(configDescriptor);
Assert.assertNotNull(configDescriptor.getCallbackDescriptor(TestSecured.class));
List<Set<String>> /*return type of one callback*/
callbackResult = ((TestSecured.Descriptor) configDescriptor.getExecutableCallbackDescriptor(TestSecured.class, TestSecured.Descriptor.class)).execute("param1", "param2");
Assert.assertNotNull(callbackResult);
Assert.assertEquals(1, callbackResult.size());
Assert.assertEquals(3, callbackResult.iterator().next().size());
Iterator<String> resultIterator = callbackResult.iterator().next().iterator();
//the order in the result isn't guaranteed
Set<String> expectedValues = new CopyOnWriteArraySet<String>();
expectedValues.add("param1");
expectedValues.add("param2");
expectedValues.add(SimpleTestAccessDecisionVoter1.class.getName());
while (resultIterator.hasNext()) {
String currentValue = resultIterator.next();
if (!expectedValues.remove(currentValue)) {
Assert.fail("value '" + currentValue + "' not found in the result");
}
}
Assert.assertTrue(expectedValues.isEmpty());
}
use of java.util.concurrent.CopyOnWriteArraySet in project geode by apache.
the class MBeanProxyInfoRepository method addProxyToRepository.
/**
* Add the {@link ProxyInfo} into repository for future quick access
*
* @param member Distributed Member
* @param proxyInfo Proxy Info instance
*/
protected void addProxyToRepository(DistributedMember member, ProxyInfo proxyInfo) {
ObjectName objectName = proxyInfo.getObjectName();
if (logger.isTraceEnabled()) {
logger.trace("ADDED TO PROXY REPO : {}", proxyInfo.getObjectName());
}
objectNameIndex.put(objectName, proxyInfo);
if (memberIndex.get(member) != null) {
memberIndex.get(member).add(proxyInfo.getObjectName());
} else {
Set<ObjectName> proxyInfoSet = new CopyOnWriteArraySet<ObjectName>();
proxyInfoSet.add(proxyInfo.getObjectName());
memberIndex.put(member, proxyInfoSet);
}
}
use of java.util.concurrent.CopyOnWriteArraySet in project tomee by apache.
the class WebappBeanManager method mergeBeans.
private Set<Bean<?>> mergeBeans() {
// override parent one with a "webapp" bean list
final Set<Bean<?>> allBeans = new CopyOnWriteArraySet<>();
final BeanManagerImpl parentBm = getParentBm();
if (parentBm != null) {
for (final Bean<?> bean : parentBm.getBeans()) {
if (filter.accept(bean)) {
allBeans.add(bean);
}
}
}
allBeans.addAll(super.getBeans());
return allBeans;
}
Aggregations