//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldPopulateAndUpdate() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldPopulateAndUpdate()
        {
            // GIVEN
            WithPopulator(IndexProvider.getPopulator(Descriptor, IndexSamplingConfig, heapBufferFactory(1024)), p => p.add(Updates(ValueSet1)));

            using (IndexAccessor accessor = IndexProvider.getOnlineAccessor(Descriptor, IndexSamplingConfig))
            {
                // WHEN
                using (IndexUpdater updater = accessor.NewUpdater(IndexUpdateMode.ONLINE))
                {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.List<IndexEntryUpdate<?>> updates = updates(valueSet2);
                    IList <IndexEntryUpdate <object> > updates = updates(ValueSet2);
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: for (IndexEntryUpdate<?> update : updates)
                    foreach (IndexEntryUpdate <object> update in updates)
                    {
                        updater.Process(update);
                    }
                }

                // THEN
                using (IndexReader reader = new QueryResultComparingIndexReader(accessor.NewReader()))
                {
                    int propertyKeyId = Descriptor.schema().PropertyId;
                    foreach (NodeAndValue entry in Iterables.concat(ValueSet1, ValueSet2))
                    {
                        NodeValueIterator nodes = new NodeValueIterator();
                        reader.Query(nodes, IndexOrder.NONE, false, IndexQuery.exact(propertyKeyId, entry.Value));
                        assertEquals(entry.NodeId, nodes.Next());
                        assertFalse(nodes.HasNext());
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Returns the position of the first value whose key is not less than k using
        /// binary search.
        /// </summary>
        /// <param name="k">input test key</param>
        /// <param name="s">start index</param>
        /// <param name="e">end index</param>
        /// <param name="comp">key comparator</param>
        /// <param name="keyAccessor">key accessor</param>
        /// <returns></returns>
        public static int BinarySearch(
            TK k,
            int s,
            int e,
            IComparer <TK> comp,
            IndexAccessor keyAccessor)
        {
            while (s != e)
            {
                var mid = (s + e) / 2;
                var c   = comp.Compare(keyAccessor(mid), k);
                if (c < 0)
                {
                    s = mid + 1;
                }
                else if (c > 0)
                {
                    e = mid;
                }
                else
                {
                    // Need to return the first value whose key is not less than k, which
                    // requires continuing the binary search. Note that we are guaranteed
                    // that the result is an exact match because if "key(mid-1) < k" the
                    // call to BinarySearchCompareTo() will return "mid".
                    return(BinarySearch(k, s, mid, comp, keyAccessor));
                }
            }

            return(s);
        }
Esempio n. 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldKeepFailedIndexesAsFailedAfterRestart() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldKeepFailedIndexesAsFailedAfterRestart()
        {
            // Given
            IndexPopulator indexPopulator = mock(typeof(IndexPopulator));

            when(_mockedIndexProvider.getPopulator(any(typeof(StoreIndexDescriptor)), any(typeof(IndexSamplingConfig)), any())).thenReturn(indexPopulator);
            IndexAccessor indexAccessor = mock(typeof(IndexAccessor));

            when(_mockedIndexProvider.getOnlineAccessor(any(typeof(StoreIndexDescriptor)), any(typeof(IndexSamplingConfig)))).thenReturn(indexAccessor);
            StartDb();
            CreateIndex(_myLabel);
            RotateLogsAndCheckPoint();

            // And Given
            KillDb();
            when(_mockedIndexProvider.getInitialState(any(typeof(StoreIndexDescriptor)))).thenReturn(InternalIndexState.FAILED);

            // When
            StartDb();

            // Then
            assertThat(getIndexes(_db, _myLabel), inTx(_db, hasSize(1)));
            assertThat(getIndexes(_db, _myLabel), inTx(_db, haveState(_db, Org.Neo4j.Graphdb.schema.Schema_IndexState.Failed)));
            verify(_mockedIndexProvider, times(2)).getPopulator(any(typeof(StoreIndexDescriptor)), any(typeof(IndexSamplingConfig)), any());
        }
Esempio n. 4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void makeSureIndexHasSomeData(org.neo4j.kernel.api.index.IndexProvider provider) throws java.io.IOException, org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException
        private void MakeSureIndexHasSomeData(IndexProvider provider)
        {
            using (IndexAccessor accessor = provider.GetOnlineAccessor(_storeIndexDescriptor, _samplingConfig), IndexUpdater updater = accessor.NewUpdater(IndexUpdateMode.ONLINE))
            {
                updater.Process(IndexEntryUpdate.add(1, _storeIndexDescriptor, Values.of("some string")));
            }
        }
Esempio n. 5
0
        private static BoundedIterable <long> MockSingleAllEntriesReader(IndexAccessor targetAccessor, IList <long> entries)
        {
            BoundedIterable <long> allEntriesReader = MockedAllEntriesReader(entries);

            when(targetAccessor.NewAllEntriesReader()).thenReturn(allEntriesReader);
            return(allEntriesReader);
        }
Esempio n. 6
0
        /// <summary>
        /// This test come from a support case where dropping an index would block forever after index sampling failed.
        /// <para>
        /// A fusion index has multiple <seealso cref="IndexSampler index samplers"/> that are called sequentially. If one fails, then the other will never be invoked.
        /// This was a problem for <seealso cref="LuceneIndexSampler"/>. It owns a <seealso cref="org.neo4j.helpers.TaskControl"/> that it will try to release in try-finally
        /// in <seealso cref="LuceneIndexSampler.sampleIndex()"/>. But it never gets here because a prior <seealso cref="IndexSampler"/> fails.
        /// </para>
        /// <para>
        /// Because the <seealso cref="org.neo4j.helpers.TaskControl"/> was never released the lucene accessor would block forever, waiting for
        /// <seealso cref="TaskCoordinator.awaitCompletion()"/>.
        /// </para>
        /// <para>
        /// This situation was solved by making <seealso cref="IndexSampler"/> <seealso cref="System.IDisposable"/> and include it in try-with-resource together with
        /// <seealso cref="IndexReader"/> that created it.
        /// </para>
        /// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(timeout = 5_000L) public void failedIndexSamplingMustNotPreventIndexDrop() throws java.io.IOException, org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void FailedIndexSamplingMustNotPreventIndexDrop()
        {
            LuceneIndexProvider luceneProvider = luceneProvider();

            MakeSureIndexHasSomeData(luceneProvider);                 // Otherwise no sampler will be created.

            IndexProvider       failingProvider = failingProvider();
            FusionIndexProvider fusionProvider  = CreateFusionProvider(luceneProvider, failingProvider);

            using (IndexAccessor fusionAccessor = fusionProvider.GetOnlineAccessor(_storeIndexDescriptor, _samplingConfig))
            {
                IndexSamplingJob indexSamplingJob = CreateIndexSamplingJob(fusionAccessor);

                // Call run from other thread
                try
                {
                    indexSamplingJob.run();
                }
                catch (Exception e)
                {
                    assertSame(e, _sampleException);
                }

                // then
                fusionAccessor.Drop();
                // should not block forever
            }
        }
 /// <summary>
 /// Class constructor
 /// </summary>
 /// <param name="document">Document to perform operations on</param>
 /// <param name="fullName">Full path name of document</param>
 public PTWordprocessingDocument(OpenXmlSDK.WordprocessingDocument document, string fullName)
     : base()
 {
     Document         = document;
     FullName         = fullName;
     InnerContent     = new WordprocessingDocumentManager(this);
     Comments         = new CommentAccessor(this);
     Changes          = new ChangeAccessor(this);
     Headers          = new HeaderAccessor(this);
     Footer           = new FooterAccessor(this);
     Setting          = new SettingAccessor(this);
     CustomXml        = new CustomXmlAccessor(this);
     Background       = new BackgroundAccessor(this);
     Style            = new StyleAccessor(this);
     Format           = new ContentFormatAccessor(this);
     Picture          = new PictureAccessor(this);
     Watermark        = new WatermarkAccesor(this);
     Theme            = new ThemeAccessor(this);
     TOC              = new TOCAccessor(this);
     TOF              = new TOFAccessor(this);
     TOA              = new TOAAccessor(this);
     Index            = new IndexAccessor(this);
     CoreProperties   = new CorePropertiesAccesor(this);
     CustomProperties = new CustomPropertiesAccesor(this);
 }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldProvidePopulatorThatAcceptsDuplicateEntries() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
            public virtual void ShouldProvidePopulatorThatAcceptsDuplicateEntries()
            {
                // when
                long offset = ValueSet1.Count;

                WithPopulator(IndexProvider.getPopulator(Descriptor, IndexSamplingConfig, heapBufferFactory(1024)), p =>
                {
                    p.add(Updates(ValueSet1, 0));
                    p.add(Updates(ValueSet1, offset));
                });

                // then
                using (IndexAccessor accessor = IndexProvider.getOnlineAccessor(Descriptor, IndexSamplingConfig))
                {
                    using (IndexReader reader = new QueryResultComparingIndexReader(accessor.NewReader()))
                    {
                        int propertyKeyId = Descriptor.schema().PropertyId;
                        foreach (NodeAndValue entry in ValueSet1)
                        {
                            NodeValueIterator nodes = new NodeValueIterator();
                            reader.Query(nodes, IndexOrder.NONE, false, IndexQuery.exact(propertyKeyId, entry.Value));
                            assertEquals(entry.Value.ToString(), asSet(entry.NodeId, entry.NodeId + offset), PrimitiveLongCollections.toSet(nodes));
                        }
                    }
                }
            }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldApplyUpdatesIdempotently() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldApplyUpdatesIdempotently()
        {
            // GIVEN
            IndexSamplingConfig indexSamplingConfig = new IndexSamplingConfig(Config.defaults());
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.values.storable.Value propertyValue = org.neo4j.values.storable.Values.of("value1");
            Value propertyValue = Values.of("value1");

            WithPopulator(IndexProvider.getPopulator(Descriptor, indexSamplingConfig, heapBufferFactory(1024)), p =>
            {
                long nodeId = 1;

                // update using populator...
                IndexEntryUpdate <SchemaDescriptor> update = add(nodeId, Descriptor.schema(), propertyValue);
                p.add(singletonList(update));
                // ...is the same as update using updater
                using (IndexUpdater updater = p.newPopulatingUpdater((node, propertyId) => propertyValue))
                {
                    updater.Process(update);
                }
            });

            // THEN
            using (IndexAccessor accessor = IndexProvider.getOnlineAccessor(Descriptor, indexSamplingConfig))
            {
                using (IndexReader reader = new QueryResultComparingIndexReader(accessor.NewReader()))
                {
                    int          propertyKeyId = Descriptor.schema().PropertyId;
                    LongIterator nodes         = reader.Query(IndexQuery.exact(propertyKeyId, propertyValue));
                    assertEquals(asSet(1L), PrimitiveLongCollections.toSet(nodes));
                }
            }
        }
Esempio n. 10
0
        private IndexSamplingJob CreateIndexSamplingJob(IndexAccessor fusionAccessor)
        {
            IndexStoreView                storeView  = Org.Neo4j.Kernel.Impl.Api.index.IndexStoreView_Fields.Empty;
            IndexProxyAdapter             indexProxy = new IndexProxyAdapterAnonymousInnerClass(this, fusionAccessor);
            OnlineIndexSamplingJobFactory onlineIndexSamplingJobFactory = new OnlineIndexSamplingJobFactory(storeView, simpleNameLookup, Instance);

            return(onlineIndexSamplingJobFactory.Create(1, indexProxy));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void before() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void Before()
        {
            IndexSamplingConfig indexSamplingConfig = new IndexSamplingConfig(Config.defaults());
            IndexPopulator      populator           = IndexProvider.getPopulator(Descriptor, indexSamplingConfig, heapBufferFactory(1024));

            populator.Create();
            populator.Close(true);
            Accessor = IndexProvider.getOnlineAccessor(Descriptor, indexSamplingConfig);
        }
Esempio n. 12
0
 internal OnlineIndexProxy(CapableIndexDescriptor capableIndexDescriptor, IndexAccessor accessor, IndexStoreView storeView, bool forcedIdempotentMode)
 {
     Debug.Assert(accessor != null);
     this._indexId = capableIndexDescriptor.Id;
     this._capableIndexDescriptor = capableIndexDescriptor;
     this.Accessor              = accessor;
     this._storeView            = storeView;
     this._forcedIdempotentMode = forcedIdempotentMode;
     this._indexCountsRemover   = new IndexCountsRemover(storeView, _indexId);
 }
Esempio n. 13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void closeMustThrowIfOneThrow() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void CloseMustThrowIfOneThrow()
        {
            //noinspection ForLoopReplaceableByForEach - aliveAccessors is updated in initiateMocks()
            for (int i = 0; i < _aliveAccessors.Length; i++)
            {
                IndexAccessor accessor = _aliveAccessors[i];
                verifyFusionCloseThrowOnSingleCloseThrow(accessor, _fusionIndexAccessor);
                InitiateMocks();
            }
        }
Esempio n. 14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void closeMustCloseOthersIfOneThrow() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void CloseMustCloseOthersIfOneThrow()
        {
            //noinspection ForLoopReplaceableByForEach - aliveAccessors is updated in initiateMocks()
            for (int i = 0; i < _aliveAccessors.Length; i++)
            {
                IndexAccessor accessor = _aliveAccessors[i];
                verifyOtherIsClosedOnSingleThrow(accessor, _fusionIndexAccessor, without(_aliveAccessors, accessor));
                InitiateMocks();
            }
        }
        public void GetValues_FromAssignedInt_ReturnsAssignedInt()
        {
            const int initialValue = 12345;
            var item = new Dummy { IntProp = initialValue };

            var property = GetProperty("IntProp");
            var indexAccessor = new IndexAccessor(property);
            var retrievedValues = indexAccessor.GetValues(item);

            CollectionAssert.AreEqual(new[] { initialValue }, retrievedValues);
        }
        public void GetValues_FromAssignedString_ReturnsAssignedString()
        {
            const string initialValue = "Hello tester!";
            var item = new Dummy { StringProp = initialValue };

            var property = GetProperty("StringProp");
            var indexAccessor = new IndexAccessor(property);
            var retrievedValues = indexAccessor.GetValues(item);

            CollectionAssert.AreEqual(new[] { initialValue }, retrievedValues);
        }
        public void GetValues_FromNullableDecimalWithNullValue_ReturnsNull()
        {
            decimal? initialValue = null;
            var item = new Dummy { NullableDecimalProp = initialValue };

            var property = GetProperty("NullableDecimalProp");
            var indexAccessor = new IndexAccessor(property);
            var retrievedValues = indexAccessor.GetValues(item);

            Assert.IsNull(retrievedValues);
        }
Esempio n. 18
0
        public virtual void Remove(StoreIndexDescriptor descriptor)
        {
            IndexAccessor remove = _accessors.remove(descriptor.Id);

            if (remove != null)
            {
                remove.Dispose();
            }
            _onlineIndexRules.Remove(descriptor);
            _notOnlineIndexRules.Remove(descriptor);
        }
	    protected virtual IIndexAccessor[] GetIndexAccessors(IStructureType structureType)
        {
        	var accessors = new IIndexAccessor[structureType.IndexableProperties.Length];

			for (var i = 0; i < accessors.Length; i++)
			{
			    var property = structureType.IndexableProperties[i];
			    accessors[i] = new IndexAccessor(property, DataTypeConverter.Convert(property));
			}

	        return accessors;
        }
Esempio n. 20
0
        protected virtual IIndexAccessor[] GetIndexAccessors(IStructureType structureType)
        {
            var accessors = new IIndexAccessor[structureType.IndexableProperties.Length];

            for (var i = 0; i < accessors.Length; i++)
            {
                var property = structureType.IndexableProperties[i];
                accessors[i] = new IndexAccessor(property, DataTypeConverter.Convert(property));
            }

            return(accessors);
        }
Esempio n. 21
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void updateAndCommit(org.neo4j.kernel.api.index.IndexAccessor accessor, Iterable<org.neo4j.kernel.api.index.IndexEntryUpdate<?>> updates) throws java.io.IOException, org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException
        private void UpdateAndCommit <T1>(IndexAccessor accessor, IEnumerable <T1> updates)
        {
            using (IndexUpdater updater = accessor.NewUpdater(IndexUpdateMode.ONLINE))
            {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: for (org.neo4j.kernel.api.index.IndexEntryUpdate<?> update : updates)
                foreach (IndexEntryUpdate <object> update in updates)
                {
                    updater.Process(update);
                }
            }
        }
        public void GetValues_FromAssignedDecimal_ReturnsAssignedDecimal()
        {
            const decimal initialValue = 12.56M;
            var item = new Dummy { DecimalProp = initialValue };

            var property = GetProperty("DecimalProp");
            var indexAccessor = new IndexAccessor(property);
            var retrievedValues = indexAccessor.GetValues(item);

            CollectionAssert.AreEqual(
                new[] { initialValue },
                retrievedValues);
        }
        public void GetValues_FromAssignedNullableDecimal_ReturnsAssignedNullableDecimal()
        {
            decimal? initialValue = 13.34M;
            var item = new Dummy { NullableDecimalProp = initialValue };

            var property = GetProperty("NullableDecimalProp");
            var indexAccessor = new IndexAccessor(property);
            var retrievedValues = indexAccessor.GetValues(item);

            CollectionAssert.AreEqual(
                new[] { initialValue.GetValueOrDefault() },
                retrievedValues);
        }
Esempio n. 24
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void addUpdates(SpatialIndexProvider provider, org.neo4j.storageengine.api.schema.StoreIndexDescriptor schemaIndexDescriptor, ValueCreatorUtil<SpatialIndexKey,NativeIndexValue> layoutUtil) throws java.io.IOException, org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException
        private void AddUpdates(SpatialIndexProvider provider, StoreIndexDescriptor schemaIndexDescriptor, ValueCreatorUtil <SpatialIndexKey, NativeIndexValue> layoutUtil)
        {
            IndexAccessor accessor = provider.GetOnlineAccessor(schemaIndexDescriptor, SamplingConfig());

            using (IndexUpdater updater = accessor.NewUpdater(ONLINE))
            {
                // when
                foreach (IndexEntryUpdate <IndexDescriptor> update in layoutUtil.SomeUpdates(_randomRule))
                {
                    updater.Process(update);
                }
            }
            accessor.Force(Org.Neo4j.Io.pagecache.IOLimiter_Fields.Unlimited);
            accessor.Dispose();
        }
Esempio n. 25
0
        private static void VerifyFailOnSingleDropFailure(IndexAccessor failingAccessor, FusionIndexAccessor fusionIndexAccessor)
        {
            UncheckedIOException expectedFailure = new UncheckedIOException(new IOException("fail"));

            doThrow(expectedFailure).when(failingAccessor).drop();
            try
            {
                fusionIndexAccessor.Drop();
                fail("Should have failed");
            }
            catch (UncheckedIOException e)
            {
                assertSame(expectedFailure, e);
            }
            doAnswer(invocation => null).when(failingAccessor).drop();
        }
Esempio n. 26
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void stressIt() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void StressIt()
        {
            Race race = new Race();
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.concurrent.atomic.AtomicReferenceArray<java.util.List<? extends org.neo4j.kernel.api.index.IndexEntryUpdate<?>>> lastBatches = new java.util.concurrent.atomic.AtomicReferenceArray<>(THREADS);
            AtomicReferenceArray <IList <IndexEntryUpdate <object> > > lastBatches = new AtomicReferenceArray <IList <IndexEntryUpdate <object> > >(THREADS);

            Generator[] generators = new Generator[THREADS];

            _populator.create();
            System.Threading.CountdownEvent insertersDone = new System.Threading.CountdownEvent(THREADS);
            ReadWriteLock updateLock = new ReentrantReadWriteLock(true);

            for (int i = 0; i < THREADS; i++)
            {
                race.AddContestant(Inserter(lastBatches, generators, insertersDone, updateLock, i), 1);
            }
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.Collection<org.neo4j.kernel.api.index.IndexEntryUpdate<?>> updates = new java.util.ArrayList<>();
            ICollection <IndexEntryUpdate <object> > updates = new List <IndexEntryUpdate <object> >();

            race.AddContestant(Updater(lastBatches, insertersDone, updateLock, updates));

            race.Go();
            _populator.close(true);
            _populator = null;               // to let the after-method know that we've closed it ourselves

            // then assert that a tree built by a single thread ends up exactly the same
            BuildReferencePopulatorSingleThreaded(generators, updates);
            using (IndexAccessor accessor = _indexProvider.getOnlineAccessor(Descriptor, _samplingConfig), IndexAccessor referenceAccessor = _indexProvider.getOnlineAccessor(_descriptor2, _samplingConfig), IndexReader reader = accessor.NewReader(), IndexReader referenceReader = referenceAccessor.NewReader())
            {
                SimpleNodeValueClient entries          = new SimpleNodeValueClient();
                SimpleNodeValueClient referenceEntries = new SimpleNodeValueClient();
                reader.Query(entries, IndexOrder.NONE, HasValues, IndexQuery.exists(0));
                referenceReader.Query(referenceEntries, IndexOrder.NONE, HasValues, IndexQuery.exists(0));
                while (referenceEntries.Next())
                {
                    assertTrue(entries.Next());
                    assertEquals(referenceEntries.Reference, entries.Reference);
                    if (HasValues)
                    {
                        assertEquals(ValueTuple.of(referenceEntries.Values), ValueTuple.of(entries.Values));
                    }
                }
                assertFalse(entries.Next());
            }
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void assertHasAllValues(java.util.List<NodeAndValue> values) throws java.io.IOException, org.neo4j.internal.kernel.api.exceptions.schema.IndexNotApplicableKernelException
        private void AssertHasAllValues(IList <NodeAndValue> values)
        {
            using (IndexAccessor accessor = IndexProvider.getOnlineAccessor(Descriptor, IndexSamplingConfig))
            {
                using (IndexReader reader = new QueryResultComparingIndexReader(accessor.NewReader()))
                {
                    int propertyKeyId = Descriptor.schema().PropertyId;
                    foreach (NodeAndValue entry in values)
                    {
                        NodeValueIterator nodes = new NodeValueIterator();
                        reader.Query(nodes, IndexOrder.NONE, false, IndexQuery.exact(propertyKeyId, entry.Value));
                        assertEquals(entry.NodeId, nodes.Next());
                        assertFalse(nodes.HasNext());
                    }
                }
            }
        }
Esempio n. 28
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldProvidePopulatorThatAcceptsDuplicateEntries() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
            public virtual void ShouldProvidePopulatorThatAcceptsDuplicateEntries()
            {
                // when
                IndexSamplingConfig indexSamplingConfig = new IndexSamplingConfig(Config.defaults());

                WithPopulator(IndexProvider.getPopulator(Descriptor, indexSamplingConfig, heapBufferFactory(1024)), p => p.add(Arrays.asList(add(1, Descriptor.schema(), "v1", "v2"), add(2, Descriptor.schema(), "v1", "v2"))));

                // then
                using (IndexAccessor accessor = IndexProvider.getOnlineAccessor(Descriptor, indexSamplingConfig))
                {
                    using (IndexReader reader = new QueryResultComparingIndexReader(accessor.NewReader()))
                    {
                        LongIterator nodes = reader.Query(IndexQuery.exact(1, "v1"), IndexQuery.exact(1, "v2"));
                        assertEquals(asSet(1L, 2L), PrimitiveLongCollections.toSet(nodes));
                    }
                }
            }
        /// <summary>
        /// Class constructor
        /// </summary>
        /// <param name="filePath">Path of document to load</param>
        /// <param name="createNew">Whether create a new document or load contents from existing one</param>
        public PTWordprocessingDocument(string filePath, bool createNew)
            : base()
        {
            try
            {
                if (createNew)
                {
                    Document = OpenXmlSDK.WordprocessingDocument.Create(filePath, DocumentFormat.OpenXml.WordprocessingDocumentType.Document);
                }
                else
                {
                    Document = OpenXmlSDK.WordprocessingDocument.Open(filePath, true);
                }
                FullName = filePath;

                InnerContent = new WordprocessingDocumentManager(this);
                Comments     = new CommentAccessor(this);
                Changes      = new ChangeAccessor(this);
                Headers      = new HeaderAccessor(this);
                Footer       = new FooterAccessor(this);
                Setting      = new SettingAccessor(this);
                CustomXml    = new CustomXmlAccessor(this);
                Background   = new BackgroundAccessor(this);
                Style        = new StyleAccessor(this);
                Format       = new ContentFormatAccessor(this);
                Picture      = new PictureAccessor(this);
                Watermark    = new WatermarkAccesor(this);
                Theme        = new ThemeAccessor(this);
                TOC          = new TOCAccessor(this);
                TOF          = new TOFAccessor(this);
                TOA          = new TOAAccessor(this);
                Index        = new IndexAccessor(this);
            }
            catch (OpenXmlSDK.OpenXmlPackageException ope)
            {
                throw new Exception("Bad formed OpenXml package", ope);
            }
            catch (FileFormatException ffe) {
                throw new Exception("File contains corrupted data", ffe);
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 30
0
        /* getOnlineAccessor */

//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotCheckConflictsWhenApplyingUpdatesInOnlineAccessor() throws java.io.IOException, org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotCheckConflictsWhenApplyingUpdatesInOnlineAccessor()
        {
            // given
            _provider = NewProvider();

            // when
            StoreIndexDescriptor descriptor = DescriptorUnique();

            using (IndexAccessor accessor = _provider.getOnlineAccessor(descriptor, SamplingConfig()), IndexUpdater indexUpdater = accessor.NewUpdater(IndexUpdateMode.ONLINE))
            {
                Value value = SomeValue();
                indexUpdater.Process(IndexEntryUpdate.add(1, descriptor.Schema(), value));

                // then
                // ... expect no failure on duplicate value
                indexUpdater.Process(IndexEntryUpdate.add(2, descriptor.Schema(), value));
            }
        }
Esempio n. 31
0
        public void ToSql_ForByteArray_ThrowsException()
        {
            var propertyFake = new Mock <IStructureProperty>();

            propertyFake.Setup(x => x.Path).Returns("Bytes");
            propertyFake.Setup(x => x.IsEnumerable).Returns(true);
            propertyFake.Setup(x => x.ElementDataType).Returns(typeof(byte));
            propertyFake.Setup(x => x.DataType).Returns(typeof(byte[]));
            propertyFake.Setup(x => x.IsRootMember).Returns(true);

            var iac = new IndexAccessor(propertyFake.Object, _dataTypeConverter.Convert(propertyFake.Object));

            var ex = Assert.Throws <SisoDbException>(() => _translator.ToDbType(iac.DataType));

            Assert.AreEqual(
                ExceptionMessages.DbDataTypeTranslator_UnsupportedType.Inject("Byte[]"),
                ex.Message);
        }
Esempio n. 32
0
        private static void ConsistencyCheckSchemaIndexes(IndexAccessors indexes, ConsistencyReporter report, ProgressListener listener)
        {
            IList <StoreIndexDescriptor> rulesToRemove = new List <StoreIndexDescriptor>();

            foreach (StoreIndexDescriptor onlineRule in indexes.OnlineRules())
            {
                ConsistencyReporter.FormattingDocumentedHandler handler = report.FormattingHandler(RecordType.INDEX);
                ReporterFactory reporterFactory = new ReporterFactory(handler);
                IndexAccessor   accessor        = indexes.AccessorFor(onlineRule);
                if (!accessor.ConsistencyCheck(reporterFactory))
                {
                    rulesToRemove.Add(onlineRule);
                }
                handler.UpdateSummary();
                listener.Add(1);
            }
            foreach (StoreIndexDescriptor toRemove in rulesToRemove)
            {
                indexes.Remove(toRemove);
            }
        }
Esempio n. 33
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBeAbleToRecoverAndUpdateOnlineIndex() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldBeAbleToRecoverAndUpdateOnlineIndex()
        {
            // Given
            StartDb();

            IndexPopulator populator = mock(typeof(IndexPopulator));

            when(_mockedIndexProvider.getPopulator(any(typeof(StoreIndexDescriptor)), any(typeof(IndexSamplingConfig)), any())).thenReturn(populator);
            when(populator.SampleResult()).thenReturn(new IndexSample());
            IndexAccessor mockedAccessor = mock(typeof(IndexAccessor));

            when(mockedAccessor.NewUpdater(any(typeof(IndexUpdateMode)))).thenReturn(SwallowingIndexUpdater.INSTANCE);
            when(_mockedIndexProvider.getOnlineAccessor(any(typeof(StoreIndexDescriptor)), any(typeof(IndexSamplingConfig)))).thenReturn(mockedAccessor);
            CreateIndexAndAwaitPopulation(_myLabel);
            // rotate logs
            RotateLogsAndCheckPoint();
            // make updates
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.Set<org.neo4j.kernel.api.index.IndexEntryUpdate<?>> expectedUpdates = createSomeBananas(myLabel);
            ISet <IndexEntryUpdate <object> > expectedUpdates = CreateSomeBananas(_myLabel);

            // And Given
            KillDb();
            when(_mockedIndexProvider.getInitialState(any(typeof(StoreIndexDescriptor)))).thenReturn(InternalIndexState.ONLINE);
            GatheringIndexWriter writer = new GatheringIndexWriter();

            when(_mockedIndexProvider.getOnlineAccessor(any(typeof(StoreIndexDescriptor)), any(typeof(IndexSamplingConfig)))).thenReturn(writer);

            // When
            StartDb();

            // Then
            assertThat(getIndexes(_db, _myLabel), inTx(_db, hasSize(1)));
            assertThat(getIndexes(_db, _myLabel), inTx(_db, haveState(_db, Org.Neo4j.Graphdb.schema.Schema_IndexState.Online)));
            verify(_mockedIndexProvider, times(1)).getPopulator(any(typeof(StoreIndexDescriptor)), any(typeof(IndexSamplingConfig)), any());
            int onlineAccessorInvocationCount = 2;               // once when we create the index, and once when we restart the db

            verify(_mockedIndexProvider, times(onlineAccessorInvocationCount)).getOnlineAccessor(any(typeof(StoreIndexDescriptor)), any(typeof(IndexSamplingConfig)));
            assertEquals(expectedUpdates, writer.BatchedUpdates);
        }
 protected override void ProcessRecord()
 {
     foreach (var document in AllDocuments("Add-OpenXmlDocumentIndex"))
     {
         try
         {
             using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(document))
             {
                 using (WordprocessingDocument doc = streamDoc.GetWordprocessingDocument())
                 {
                     IndexAccessor.Generate(doc);
                     StyleAccessor.CreateIndexStyles(doc, stylesSourcePath, addDefaultStyles);
                 }
                 OutputDocument(streamDoc.GetModifiedDocument());
             }
         }
         catch (Exception e)
         {
             WriteError(PowerToolsExceptionHandling.GetExceptionErrorRecord(e, document));
         }
     }
 }
Esempio n. 35
0
        private void InitiateMocks()
        {
            IndexSlot[] activeSlots = FusionVersion.aliveSlots();
            _accessors = new Dictionary <IndexSlot, IndexAccessor>(typeof(IndexSlot));
            fill(_accessors, Org.Neo4j.Kernel.Api.Index.IndexAccessor_Fields.Empty);
            _aliveAccessors = new IndexAccessor[activeSlots.Length];
            for (int i = 0; i < activeSlots.Length; i++)
            {
                IndexAccessor mock = mock(typeof(IndexAccessor));
                _aliveAccessors[i] = mock;
                switch (activeSlots[i])
                {
                case STRING:
                    _accessors[STRING] = mock;
                    break;

                case NUMBER:
                    _accessors[NUMBER] = mock;
                    break;

                case SPATIAL:
                    _accessors[SPATIAL] = mock;
                    break;

                case TEMPORAL:
                    _accessors[TEMPORAL] = mock;
                    break;

                case LUCENE:
                    _accessors[LUCENE] = mock;
                    break;

                default:
                    throw new Exception();
                }
            }
            _fusionIndexAccessor = new FusionIndexAccessor(FusionVersion.slotSelector(), new InstanceSelector <IndexAccessor>(_accessors), _indexDescriptor, _dropAction);
        }
Esempio n. 36
0
        /// <summary>
        /// Returns the position of the first value whose key is not less than k using
        /// linear search.
        /// </summary>
        /// <param name="k">input test key</param>
        /// <param name="s">start index</param>
        /// <param name="e">end index</param>
        /// <param name="comp">key comparator</param>
        /// <param name="keyAccessor">key accessor</param>
        /// <returns></returns>
        public static int LinearSearch(
            TK k,
            int s,
            int e,
            IComparer <TK> comp,
            IndexAccessor keyAccessor)
        {
            while (s < e)
            {
                var c = comp.Compare(keyAccessor(s), k);
                if (c == 0)
                {
                    return(s);
                }
                else if (c > 0)
                {
                    break;
                }

                ++s;
            }

            return(s);
        }
        public void GetValue_FromAssignedDateTime_ReturnsAssignedDateTime()
        {
            var initialValue = new DateTime(2010, 2, 3);
            var item = new Dummy { DateTimeProp = initialValue };

            var property = GetProperty("DateTimeProp");
            var indexAccessor = new IndexAccessor(property);
            var retrievedValues = indexAccessor.GetValues(item);

            CollectionAssert.AreEqual(
                new[] { initialValue },
                retrievedValues);
        }
        public void GetValues_FromNullString_ReturnsNullString()
        {
            const string initialValue = null;
            var item = new Dummy { StringProp = initialValue };

            var property = GetProperty("StringProp");
            var indexAccessor = new IndexAccessor(property);
            var retrievedValues = indexAccessor.GetValues(item);

            Assert.IsNull(retrievedValues);
        }
        public void GetValue_FromAssignedBool_ReturnsAssignedBool()
        {
            const bool initialValue = true;
            var item = new Dummy { BoolProp = initialValue };

            var property = GetProperty("BoolProp");
            var indexAccessor = new IndexAccessor(property);
            var retrievedValues = indexAccessor.GetValues(item);

            CollectionAssert.AreEqual(new[] { initialValue }, retrievedValues);
        }