Example #1
0
        public void BinaryTreeTest_DiffSerialization(bool useFile, bool containedInSingleBlob, bool recreateIndex, bool neverIncludeReferenceToPreviousBuffer, bool useConsolidatedMemory)
        {
            List <PersistentIndex> indices     = new List <PersistentIndex>();
            IBlobManager           blobManager = useFile ? new FileBlobManager() : new InMemoryBlobManager();
            string fullPath = GetPathForIndexAndBlobs(useFile, true);

            if (fullPath == null)
            {
                return;
            }
            int round                      = 0;
            int numRounds                  = 2; // DEBUG 10
            int numChangesFirstRound       = 1; // DEBUG 10
            int numChangesSubsequentRounds = 1; // DEBUG 3

            MultipleRoundsOfRandomChanges(numRounds, numChangesFirstRound, numChangesSubsequentRounds, () =>
            {
                //Debug.WriteLine($"Round {round}");

                LazinatorSerializationOptions options = neverIncludeReferenceToPreviousBuffer ? new LazinatorSerializationOptions(IncludeChildrenMode.IncludeAllChildren, false, false, true, int.MaxValue, int.MaxValue) : new LazinatorSerializationOptions(IncludeChildrenMode.IncludeAllChildren, false, false, true, 20, 5);
                LazinatorMemory multipleBufferResult  = BinaryTree.SerializeLazinator(options);

                // DEBUG
                Debug.WriteLine("Multiple buffer result:");
                Debug.WriteLine(multipleBufferResult.ToStringByChunk());
                Debug.WriteLine($"Consolidated{round}: " + multipleBufferResult.ToStringConsolidated());

                // Write to one or more blobs
                var index = (useConsolidatedMemory || indices == null || !indices.Any()) ? new PersistentIndex(fullPath, blobManager, containedInSingleBlob) : new PersistentIndex(indices.Last());
                index.PersistLazinatorMemory(multipleBufferResult);
                indices.Add(index);

                if (recreateIndex)
                {
                    index = PersistentIndex.ReadFromBlob(blobManager, fullPath, null, index.IndexVersion);
                }
                var revisedMemory = index.GetLazinatorMemory();
                if (useConsolidatedMemory)
                {
                    var consolidatedMemory = revisedMemory.GetConsolidatedMemory();
                    revisedMemory          = new LazinatorMemory(consolidatedMemory);
                    if (round != numRounds - 1)
                    {
                        indices.RemoveAt(0); // with consolidated memory, we're not using diff serialization
                    }
                }

                // DEBUG
                Debug.WriteLine("Revised memory result:");
                Debug.WriteLine(revisedMemory.ToStringByChunk());
                Debug.WriteLine($"Consolidated{round}: " + revisedMemory.ToStringConsolidated());

                BinaryTree = new LazinatorBinaryTree <WDouble>(revisedMemory);
                round++;
            });
            DeleteChunksAndIndex(useConsolidatedMemory, indices, blobManager);
        }
Example #2
0
        public void BinaryTreeTest_RecreatingManually()
        {
            // This test both confirms that binary trees work without diff serialization and also helps show what the memory should look like
            // at each stage. This makes it easier to find problems if tests using diff serialization fail.
            List <PersistentIndex> indices = new List <PersistentIndex>();
            int round = 0;

            MultipleRoundsOfRandomChanges(10, 10, 5, () =>
            {
                Debug.WriteLine($"Round {round}");
                LazinatorMemory lazinatorMemory = BinaryTree.SerializeLazinator(LazinatorSerializationOptions.Default);

                Debug.WriteLine($"Consolidated{round++}: " + lazinatorMemory.ToStringConsolidated());

                BinaryTree = new LazinatorBinaryTree <WDouble>(lazinatorMemory);
            });
        }