Example #1
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 #2
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 #3
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);
                }
            }
        }