//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldFilterResults()
        public virtual void ShouldFilterResults()
        {
            // given
            IList <string> keys = new List <string>();

            for (int i = 0; i < 100; i++)
            {
                // duplicates are fine
                keys.Add(Random.nextAlphaNumericString());
            }

            RawCursor <Hit <StringIndexKey, NativeIndexValue>, IOException> cursor = new ResultCursor(keys.GetEnumerator());

            IndexQuery[] predicates          = new IndexQuery[] { mock(typeof(IndexQuery)) };
            System.Predicate <string> filter = @string => @string.contains("a");
            when(predicates[0].AcceptsValue(any(typeof(Value)))).then(invocation => filter((( TextValue )invocation.getArgument(0)).stringValue()));
            FilteringNativeHitIterator <StringIndexKey, NativeIndexValue> iterator = new FilteringNativeHitIterator <StringIndexKey, NativeIndexValue>(cursor, new List <RawCursor <Hit <KEY, VALUE>, IOException> >(), predicates);
            IList <long> result = new List <long>();

            // when
            while (iterator.hasNext())
            {
                result.Add(iterator.next());
            }

            // then
            for (int i = 0; i < keys.Count; i++)
            {
                if (filter(keys[i]))
                {
                    assertTrue(result.RemoveAt(( long )i));
                }
            }
            assertTrue(result.Count == 0);
        }
Esempio n. 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldFailBeforeCommitOnSizesLargerThanLimit()
        public virtual void ShouldFailBeforeCommitOnSizesLargerThanLimit()
        {
            // given
            CreateIndex(KEY);

            // when a string slightly longer than the native string limit
            int length = 5_000;

            try
            {
                using (Transaction tx = Db.beginTx())
                {
                    Db.createNode(LABEL).setProperty(KEY, Random.nextAlphaNumericString(length, length));
                    tx.Success();
                }
                fail("Should have failed");
            }
            catch (System.ArgumentException e)
            {
                // then good
                assertThat(e.Message, containsString("Property value size is too large for index. Please see index documentation for limitations."));
            }
        }
Esempio n. 3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void shouldWriteAndReadEntriesOfRandomSizes(int minKeySize, int maxKeySize, int minValueSize, int maxValueSize) throws java.io.IOException
        private void ShouldWriteAndReadEntriesOfRandomSizes(int minKeySize, int maxKeySize, int minValueSize, int maxValueSize)
        {
            // given
            using (GBPTree <RawBytes, RawBytes> tree = CreateIndex(Layout()))
            {
                // when
                ISet <string> generatedStrings             = new HashSet <string>();
                IList <Pair <RawBytes, RawBytes> > entries = new List <Pair <RawBytes, RawBytes> >();
                using (Writer <RawBytes, RawBytes> writer = tree.Writer())
                {
                    for (int i = 0; i < 1_000; i++)
                    {
                        // value, based on i
                        RawBytes value = new RawBytes();
                        value.Bytes = new sbyte[Random.Next(minValueSize, maxValueSize)];
                        Random.NextBytes(value.Bytes);

                        // key, randomly generated
                        string @string;
                        do
                        {
                            @string = Random.nextAlphaNumericString(minKeySize, maxKeySize);
                        } while (!generatedStrings.Add(@string));
                        RawBytes key = new RawBytes();
                        key.Bytes = UTF8.encode(@string);
                        entries.Add(Pair.of(key, value));

                        // write
                        writer.Put(key, value);
                    }
                }

                // then
                foreach (Pair <RawBytes, RawBytes> entry in entries)
                {
                    using (RawCursor <Hit <RawBytes, RawBytes>, IOException> seek = tree.Seek(entry.First(), entry.First()))
                    {
                        assertTrue(seek.Next());
                        assertArrayEquals(entry.First().Bytes, seek.get().key().bytes);
                        assertArrayEquals(entry.Other().Bytes, seek.get().value().bytes);
                        assertFalse(seek.Next());
                    }
                }
            }
        }
Esempio n. 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldStoreAndLoadStrings()
        public virtual void ShouldStoreAndLoadStrings()
        {
            // given
            using (StringCollisionValues values = new StringCollisionValues(Factory.apply(Storage), 10_000))
            {
                // when
                long[]   offsets = new long[100];
                string[] strings = new string[offsets.Length];
                for (int i = 0; i < offsets.Length; i++)
                {
                    string @string = random.nextAlphaNumericString();
                    offsets[i] = values.Add(@string);
                    strings[i] = @string;
                }

                // then
                for (int i = 0; i < offsets.Length; i++)
                {
                    assertEquals(strings[i], values.Get(offsets[i]));
                }
            }
        }