Example #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @ParameterizedTest @EnumSource(DescriptorFactory.class) void shouldLookupSingleKeyDescriptors(DescriptorFactory factory)
        internal virtual void ShouldLookupSingleKeyDescriptors(DescriptorFactory factory)
        {
            // given
            SchemaDescriptorLookupSet <SchemaDescriptor> set = new SchemaDescriptorLookupSet <SchemaDescriptor>();
            SchemaDescriptor expected = factory.descriptor(1, 2);

            set.Add(expected);

            // when
            ISet <SchemaDescriptor> descriptors = new HashSet <SchemaDescriptor>();

            set.MatchingDescriptorsForPartialListOfProperties(descriptors, Longs(1), Ints(2));

            // then
            assertEquals(asSet(expected), descriptors);
        }
Example #2
0
 private IndexMap(MutableLongObjectMap <IndexProxy> indexesById, IDictionary <SchemaDescriptor, IndexProxy> indexesByDescriptor, MutableObjectLongMap <SchemaDescriptor> indexIdsByDescriptor, MutableLongObjectMap <IndexBackedConstraintDescriptor> uniquenessConstraintsById)
 {
     this._indexesById                      = indexesById;
     this._indexesByDescriptor              = indexesByDescriptor;
     this._indexIdsByDescriptor             = indexIdsByDescriptor;
     this._uniquenessConstraintsById        = uniquenessConstraintsById;
     this._descriptorsByLabelThenProperty   = new SchemaDescriptorLookupSet <SchemaDescriptor>();
     this._descriptorsByReltypeThenProperty = new SchemaDescriptorLookupSet <SchemaDescriptor>();
     foreach (SchemaDescriptor schema in indexesByDescriptor.Keys)
     {
         AddDescriptorToLookups(schema);
     }
     this._constraintsByLabelThenProperty   = new SchemaDescriptorLookupSet <IndexBackedConstraintDescriptor>();
     this._constraintsByRelTypeThenProperty = new SchemaDescriptorLookupSet <IndexBackedConstraintDescriptor>();
     foreach (IndexBackedConstraintDescriptor constraint in uniquenessConstraintsById.values())
     {
         AddConstraintToLookups(constraint);
     }
 }
Example #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @ParameterizedTest @MethodSource("nodeAndRelationshipEntityTypes") void shouldMatchOnAnyEntityAndPropertyTokenForPartialPropertySchemaType(org.neo4j.storageengine.api.EntityType entityType)
        internal virtual void ShouldMatchOnAnyEntityAndPropertyTokenForPartialPropertySchemaType(EntityType entityType)
        {
            // given
            SchemaDescriptorLookupSet <SchemaDescriptor> set = new SchemaDescriptorLookupSet <SchemaDescriptor>();
            MultiTokenSchemaDescriptor descriptor1           = SchemaDescriptorFactory.multiToken(Ints(0, 1, 2), entityType, 3, 4, 5);
            MultiTokenSchemaDescriptor descriptor2           = SchemaDescriptorFactory.multiToken(Ints(0, 1), entityType, 3, 4);
            MultiTokenSchemaDescriptor descriptor3           = SchemaDescriptorFactory.multiToken(Ints(0, 2), entityType, 4, 5);

            set.Add(descriptor1);
            set.Add(descriptor2);
            set.Add(descriptor3);

            // given that this test revolves around entity tokens 0,1,2 and property tokens 3,4,5 these 3 descriptors below matches either
            // only those tokens for entity or property or neither. I.e. these should never be included in matching results
            set.Add(SchemaDescriptorFactory.multiToken(Ints(3, 4), entityType, 4, 5));
            set.Add(SchemaDescriptorFactory.multiToken(Ints(0, 1), entityType, 6, 7));
            set.Add(SchemaDescriptorFactory.multiToken(Ints(3, 4), entityType, 6, 7));

            // when matching these descriptors (in this case partial/complete list doesn't quite matter because the descriptors
            // themselves are partially matched anyway.
            ISet <SchemaDescriptor> descriptors1        = new HashSet <SchemaDescriptor>();
            ISet <SchemaDescriptor> descriptors1Partial = new HashSet <SchemaDescriptor>();
            ISet <SchemaDescriptor> descriptors2        = new HashSet <SchemaDescriptor>();
            ISet <SchemaDescriptor> descriptors2Partial = new HashSet <SchemaDescriptor>();
            ISet <SchemaDescriptor> descriptors3        = new HashSet <SchemaDescriptor>();
            ISet <SchemaDescriptor> descriptors3Partial = new HashSet <SchemaDescriptor>();

            set.MatchingDescriptorsForCompleteListOfProperties(descriptors1, Longs(0, 1), Ints(4, 5));
            set.MatchingDescriptorsForPartialListOfProperties(descriptors1Partial, Longs(0, 1), Ints(4, 5));
            set.MatchingDescriptorsForCompleteListOfProperties(descriptors2, Longs(0), Ints(3));
            set.MatchingDescriptorsForPartialListOfProperties(descriptors2Partial, Longs(0), Ints(3));
            set.MatchingDescriptorsForCompleteListOfProperties(descriptors3, Longs(1), Ints(5));
            set.MatchingDescriptorsForPartialListOfProperties(descriptors3Partial, Longs(1), Ints(5));

            // then
            assertEquals(asSet(descriptor1, descriptor2, descriptor3), descriptors1);
            assertEquals(asSet(descriptor1, descriptor2, descriptor3), descriptors1Partial);
            assertEquals(asSet(descriptor1, descriptor2), descriptors2);
            assertEquals(asSet(descriptor1, descriptor2), descriptors2Partial);
            assertEquals(asSet(descriptor1), descriptors3);
            assertEquals(asSet(descriptor1), descriptors3Partial);
        }
Example #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @ParameterizedTest @EnumSource(DescriptorFactory.class) void shouldLookupCompositeKeyDescriptor(DescriptorFactory factory)
        internal virtual void ShouldLookupCompositeKeyDescriptor(DescriptorFactory factory)
        {
            // given
            SchemaDescriptorLookupSet <SchemaDescriptor> set = new SchemaDescriptorLookupSet <SchemaDescriptor>();
            SchemaDescriptor descriptor1 = factory.descriptor(1, 2, 3);
            SchemaDescriptor descriptor2 = factory.descriptor(1, 2, 4);
            SchemaDescriptor descriptor3 = factory.descriptor(1, 2, 5, 6);

            set.Add(descriptor1);
            set.Add(descriptor2);
            set.Add(descriptor3);

            // when
            ISet <SchemaDescriptor> descriptors = new HashSet <SchemaDescriptor>();

            set.MatchingDescriptorsForCompleteListOfProperties(descriptors, Longs(1), Ints(2, 5, 6));

            // then
            assertEquals(asSet(descriptor3), descriptors);
        }
Example #5
0
        /// <param name="changedLabels"> set of labels that have changed </param>
        /// <param name="unchangedLabels"> set of labels that are unchanged </param>
        /// <param name="sortedProperties"> set of properties </param>
        /// <param name="propertyListIsComplete"> whether or not the property list is complete. For CREATE/DELETE the list is complete, but may not be for UPDATEs. </param>
        /// <returns> set of SchemaDescriptors describing the potentially affected indexes </returns>
        private ISet <T> GetRelatedDescriptors <T>(SchemaDescriptorLookupSet <T> set, long[] changedLabels, long[] unchangedLabels, int[] sortedProperties, bool propertyListIsComplete) where T : [email protected]
        {
            if (set.Empty)
            {
                return(Collections.emptySet());
            }

            ISet <T> descriptors = new HashSet <T>();

            if (propertyListIsComplete)
            {
                set.MatchingDescriptorsForCompleteListOfProperties(descriptors, changedLabels, sortedProperties);
            }
            else
            {
                // At the time of writing this the commit process won't load the complete list of property keys for an entity.
                // Because of this the matching cannot be as precise as if the complete list was known.
                // Anyway try to make the best out of it and narrow down the list of potentially related indexes as much as possible.
                if (sortedProperties.Length == 0)
                {
                    // Only labels changed. Since we don't know which properties this entity has let's include all indexes for the changed labels.
                    set.MatchingDescriptors(descriptors, changedLabels);
                }
                else if (changedLabels.Length == 0)
                {
                    // Only properties changed. Since we don't know which other properties this entity has let's include all indexes
                    // for the (unchanged) labels on this entity that has any match on any of the changed properties.
                    set.MatchingDescriptorsForPartialListOfProperties(descriptors, unchangedLabels, sortedProperties);
                }
                else
                {
                    // Both labels and properties changed.
                    // All indexes for the changed labels must be included.
                    // Also include all indexes for any of the changed or unchanged labels that has any match on any of the changed properties.
                    set.MatchingDescriptors(descriptors, changedLabels);
                    set.MatchingDescriptorsForPartialListOfProperties(descriptors, unchangedLabels, sortedProperties);
                }
            }
            return(descriptors);
        }
Example #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @ParameterizedTest @EnumSource(DescriptorFactory.class) void shouldLookupAllByEntityToken(DescriptorFactory factory)
        internal virtual void ShouldLookupAllByEntityToken(DescriptorFactory factory)
        {
            // given
            SchemaDescriptorLookupSet <SchemaDescriptor> set = new SchemaDescriptorLookupSet <SchemaDescriptor>();
            SchemaDescriptor descriptor1 = factory.descriptor(1, 2, 3);
            SchemaDescriptor descriptor2 = factory.descriptor(1, 2, 4);
            SchemaDescriptor descriptor3 = factory.descriptor(1, 2, 5, 6);
            SchemaDescriptor descriptor4 = factory.descriptor(2, 2, 3);
            SchemaDescriptor descriptor5 = factory.descriptor(3, 2, 5, 6);

            set.Add(descriptor1);
            set.Add(descriptor2);
            set.Add(descriptor3);
            set.Add(descriptor4);
            set.Add(descriptor5);

            // when
            ISet <SchemaDescriptor> descriptors = new HashSet <SchemaDescriptor>();

            set.MatchingDescriptors(descriptors, Longs(1));

            // then
            assertEquals(asSet(descriptor1, descriptor2, descriptor3), descriptors);
        }
Example #7
0
        private void ShouldAddRemoveAndLookupRandomDescriptors(bool includeIdempotentAddsAndRemoves)
        {
            // given
            IList <SchemaDescriptor> all = new List <SchemaDescriptor>();
            SchemaDescriptorLookupSet <SchemaDescriptor> set = new SchemaDescriptorLookupSet <SchemaDescriptor>();
            int highEntityKeyId         = 8;
            int highPropertyKeyId       = 8;
            int maxNumberOfEntityKeys   = 3;
            int maxNumberOfPropertyKeys = 3;

            // when/then
            for (int i = 0; i < 100; i++)
            {
                // add some
                int countToAdd = _random.Next(1, 5);
                for (int a = 0; a < countToAdd; a++)
                {
                    SchemaDescriptor descriptor = RandomSchemaDescriptor(highEntityKeyId, highPropertyKeyId, maxNumberOfEntityKeys, maxNumberOfPropertyKeys);
                    if (!includeIdempotentAddsAndRemoves && all.IndexOf(descriptor) != -1)
                    {
                        // Oops, we randomly generated a descriptor that already exists
                        continue;
                    }

                    set.Add(descriptor);
                    all.Add(descriptor);
                }

                // remove some
                int countToRemove = _random.Next(0, 2);
                for (int r = 0; r < countToRemove && all.Count > 0; r++)
                {
                    SchemaDescriptor descriptor = all.RemoveAt(_random.Next(all.Count));
                    set.Remove(descriptor);
                    if (includeIdempotentAddsAndRemoves)
                    {
                        set.Remove(descriptor);
                        while (all.Remove(descriptor))
                        {
                            // Just continue removing duplicates until all are done
                        }
                    }
                }

                // lookup
                int countToLookup = 20;
                for (int l = 0; l < countToLookup; l++)
                {
                    int[]  entityTokenIdsInts      = RandomUniqueSortedIntArray(highEntityKeyId, _random.Next(1, 3));
                    long[] entityTokenIds          = ToLongArray(entityTokenIdsInts);
                    int[]  propertyKeyIds          = RandomUniqueSortedIntArray(highPropertyKeyId, _random.Next(1, maxNumberOfPropertyKeys));
                    ISet <SchemaDescriptor> actual = new HashSet <SchemaDescriptor>();

                    // lookup by only entity tokens
                    actual.Clear();
                    set.MatchingDescriptors(actual, entityTokenIds);
                    assertEquals(ExpectedDescriptors(all, FilterByEntity(entityTokenIdsInts)), actual);

                    // lookup by partial property list
                    actual.Clear();
                    set.MatchingDescriptorsForPartialListOfProperties(actual, entityTokenIds, propertyKeyIds);
                    assertEquals(ExpectedDescriptors(all, FilterByEntityAndPropertyPartial(entityTokenIdsInts, propertyKeyIds)), actual);

                    // lookup by complete property list
                    actual.Clear();
                    set.MatchingDescriptorsForCompleteListOfProperties(actual, entityTokenIds, propertyKeyIds);
                    assertEquals(ExpectedDescriptors(all, FilterByEntityAndPropertyComplete(entityTokenIdsInts, propertyKeyIds)), actual);
                }
            }
        }
 public PropertySet(SchemaDescriptorLookupSet <T> outerInstance)
 {
     this._outerInstance = outerInstance;
 }