Search in sources :

Example 21 with CopyOnWriteArraySet

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());
    }
}
Also used : InputNode(org.neo4j.unsafe.impl.batchimport.input.InputNode) Validators(org.neo4j.kernel.impl.util.Validators) TaskExecutionPanicException(org.neo4j.unsafe.impl.batchimport.executor.TaskExecutionPanicException) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ACTUAL(org.neo4j.unsafe.impl.batchimport.input.csv.IdType.ACTUAL) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) DeserializerFactories.defaultNodeDeserializer(org.neo4j.unsafe.impl.batchimport.input.csv.DeserializerFactories.defaultNodeDeserializer) CharReadable(org.neo4j.csv.reader.CharReadable) DataFactories.defaultFormatNodeFileHeader(org.neo4j.unsafe.impl.batchimport.input.csv.DataFactories.defaultFormatNodeFileHeader) Groups(org.neo4j.unsafe.impl.batchimport.input.Groups) Rule(org.junit.Rule) Readables.wrap(org.neo4j.csv.reader.Readables.wrap) StringReader(java.io.StringReader) RandomRule(org.neo4j.test.rule.RandomRule) Assert.assertFalse(org.junit.Assert.assertFalse) Collector(org.neo4j.unsafe.impl.batchimport.input.Collector) DeserializerFactory(org.neo4j.unsafe.impl.batchimport.input.csv.InputGroupsDeserializer.DeserializerFactory) InputEntityDecorators(org.neo4j.unsafe.impl.batchimport.input.InputEntityDecorators) COMMAS(org.neo4j.unsafe.impl.batchimport.input.csv.Configuration.COMMAS) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) InputNode(org.neo4j.unsafe.impl.batchimport.input.InputNode) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) Groups(org.neo4j.unsafe.impl.batchimport.input.Groups) Collector(org.neo4j.unsafe.impl.batchimport.input.Collector) Test(org.junit.Test)

Example 22 with CopyOnWriteArraySet

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());
}
Also used : Set(java.util.Set) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) HashSet(java.util.HashSet) ViewConfigNode(org.apache.deltaspike.core.spi.config.view.ViewConfigNode) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) Test(org.junit.Test)

Example 23 with CopyOnWriteArraySet

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);
    }
}
Also used : CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) ObjectName(javax.management.ObjectName)

Example 24 with CopyOnWriteArraySet

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;
}
Also used : BeanManagerImpl(org.apache.webbeans.container.BeanManagerImpl) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) OwbBean(org.apache.webbeans.component.OwbBean) ExtensionBean(org.apache.webbeans.component.ExtensionBean) BuiltInOwbBean(org.apache.webbeans.component.BuiltInOwbBean) Bean(javax.enterprise.inject.spi.Bean)

Aggregations

CopyOnWriteArraySet (java.util.concurrent.CopyOnWriteArraySet)24 Set (java.util.Set)6 Collection (java.util.Collection)5 Test (org.junit.Test)5 CountDownLatch (java.util.concurrent.CountDownLatch)3 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 MapEvent (com.hazelcast.core.MapEvent)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 Properties (java.util.Properties)2 ObjectName (javax.management.ObjectName)2 RegistryDonePlugin (aQute.bnd.service.RegistryDonePlugin)1 DefaultExecutorServiceHandler (com.dangdang.ddframe.job.executor.handler.impl.DefaultExecutorServiceHandler)1 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1