Пример #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void process(org.neo4j.kernel.api.index.IndexEntryUpdate<?> update) throws org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException
        public override void Process <T1>(IndexEntryUpdate <T1> update)
        {
            _actual.process(update);
            if (update.UpdateMode() != REMOVED)
            {
                _touchedTuples.Add(ValueTuple.of(update.Values()));
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(timeout = TEST_TIMEOUT) public void closeWaitForUpdateToFinish() throws java.io.IOException, InterruptedException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void CloseWaitForUpdateToFinish()
        {
            // GIVEN
            System.Threading.CountdownEvent latch = new System.Threading.CountdownEvent(1);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final IndexProxy inner = new IndexProxyAdapter()
            IndexProxy inner = new IndexProxyAdapterAnonymousInnerClass3(this);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final IndexProxy outer = newContractCheckingIndexProxy(inner);
            IndexProxy outer        = NewContractCheckingIndexProxy(inner);
            Thread     actionThread = CreateActionThread(outer.close);

            outer.Start();

            // WHEN
            Thread updaterThread = RunInSeparateThread(() =>
            {
                try
                {
                    using (IndexUpdater updater = outer.NewUpdater(IndexUpdateMode.Online))
                    {
                        updater.process(null);
                        try
                        {
                            actionThread.Start();
                            latch.await();
                        }
                        catch (InterruptedException e)
                        {
                            throw new Exception(e);
                        }
                    }
                }
                catch (IndexEntryConflictException e)
                {
                    throw new Exception(e);
                }
            });

            ThreadTestUtils.awaitThreadState(actionThread, TEST_TIMEOUT, Thread.State.TIMED_WAITING);
            latch.Signal();
            updaterThread.Join();
            actionThread.Join();
        }
Пример #3
0
        private ThreadStart Updater <T1, T2>(AtomicReferenceArray <T1> lastBatches, System.Threading.CountdownEvent insertersDone, ReadWriteLock updateLock, ICollection <T2> updates) where T1 : Org.Neo4j.Kernel.Api.Index.IndexEntryUpdate <T1>
        {
            return(throwing(() =>
            {
                // Entity ids that have been removed, so that additions can reuse them
                IList <long> removed = new List <long>();
                RandomValues randomValues = RandomValues.create(new Random(Random.seed() + THREADS));
                while (insertersDone.CurrentCount > 0)
                {
                    // Do updates now and then
                    Thread.Sleep(10);
                    updateLock.writeLock().@lock();
                    try
                    {
                        using (IndexUpdater updater = _populator.newPopulatingUpdater(_nodePropertyAccessor))
                        {
                            for (int i = 0; i < THREADS; i++)
                            {
                                IList <IndexEntryUpdate <object> > batch = lastBatches.get(i);
                                if (batch != null)
                                {
                                    IndexEntryUpdate <object> update = null;
                                    switch (randomValues.Next(3))
                                    {
                                    case 0:                                              // add
                                        if (!removed.Empty)
                                        {
                                            long?id = removed.remove(randomValues.Next(removed.size()));
                                            update = add(id, Descriptor, ValueGenerator.apply(randomValues));
                                        }
                                        break;

                                    case 1:                                              // remove
                                        IndexEntryUpdate <object> removal = batch.get(randomValues.Next(batch.size()));
                                        update = remove(removal.EntityId, Descriptor, removal.values());
                                        removed.add(removal.EntityId);
                                        break;

                                    case 2:                                              // change
                                        removal = batch.get(randomValues.Next(batch.size()));
                                        change(removal.EntityId, Descriptor, removal.values(), toArray(ValueGenerator.apply(randomValues)));
                                        break;

                                    default:
                                        throw new System.ArgumentException();
                                    }
                                    if (update != null)
                                    {
                                        updater.process(update);
                                        updates.Add(update);
                                    }
                                }
                            }
                        }
                    }
                    finally
                    {
                        updateLock.writeLock().unlock();
                    }
                }
            }));
        }