public void OpenCloseInsertSeekDeleteGuidKeyStringValue() { Utility.WrapNativeSyncInvokeInMTA(() => { Uri owner = new Uri("fabric://test/btree"); LogHelper.Log("Begin construct btree"); Btree <Guid, string, GuidKeyBitConverter, UnicodeStringValueBitConverter> tree = new Btree <Guid, string, GuidKeyBitConverter, UnicodeStringValueBitConverter>(); Btree <Guid, string, GuidKeyBitConverter, UnicodeStringValueBitConverter> treeApply = new Btree <Guid, string, GuidKeyBitConverter, UnicodeStringValueBitConverter>(); LogHelper.Log("End construct btree"); // // Key configuration // LogHelper.Log("Start create key description"); GuidKeyComparison guidKeyComparison = new GuidKeyComparison(); LogHelper.Log("End create key description"); // // Storage configuration // LogHelper.Log("Start create storage description"); BtreeStorageConfigurationDescription storageDescription = new BtreeStorageConfigurationDescription(); storageDescription.IsVolatile = true; storageDescription.MaximumMemoryInMB = 1024; storageDescription.MaximumPageSizeInKB = 4; storageDescription.MaximumStorageInMB = 0; storageDescription.RetriesBeforeTimeout = 100; storageDescription.StoreDataInline = true; LogHelper.Log("End create key description"); // // Btree configuration // LogHelper.Log("Start create btree description"); BtreeConfigurationDescription btreeConfig = new BtreeConfigurationDescription(); btreeConfig.KeyComparison = guidKeyComparison.KeyComparison; btreeConfig.StorageConfiguration = storageDescription; btreeConfig.PartitionId = Guid.NewGuid(); btreeConfig.ReplicaId = 130083631515748206; LogHelper.Log("End create btree description"); // // Open the btree // LogHelper.Log("Begin open btree"); tree.OpenAsync(btreeConfig, false, CancellationToken.None).Wait(); btreeConfig.PartitionId = Guid.NewGuid(); treeApply.OpenAsync(btreeConfig, false, CancellationToken.None).Wait(); LogHelper.Log("End open btree"); long sequenceNumber = 1; BtreeKey <Guid, GuidKeyBitConverter> key1 = new BtreeKey <Guid, GuidKeyBitConverter>(Guid.NewGuid()); BtreeKey <Guid, GuidKeyBitConverter> key2 = new BtreeKey <Guid, GuidKeyBitConverter>(Guid.NewGuid()); BtreeValue <string, UnicodeStringValueBitConverter> value1 = new BtreeValue <string, UnicodeStringValueBitConverter>("value"); BtreeValue <string, UnicodeStringValueBitConverter> value2 = new BtreeValue <string, UnicodeStringValueBitConverter>(null as string); // // Insert into the btree // IRedoUndoInformation infoRedoUndoInsert1 = tree.InsertAsync(key1, value1, sequenceNumber++, CancellationToken.None).Result; IBtreeOperation insertOperation11 = treeApply.ApplyWithOutputAsync(sequenceNumber, infoRedoUndoInsert1.Redo, true, CancellationToken.None).Result; IBtreeOperation insertOperation12 = treeApply.ApplyWithOutputAsync(sequenceNumber, infoRedoUndoInsert1.Redo, false, CancellationToken.None).Result; IRedoUndoInformation infoRedoUndoInsert2 = tree.InsertAsync(key2, value2, sequenceNumber++, CancellationToken.None).Result; // // Insert again the same key from the btree // try { tree.InsertAsync(key2, value2, sequenceNumber++, CancellationToken.None).Wait(); Debug.Assert(false); } catch (AggregateException e) { if (!(e.InnerException is ArgumentException)) { Debug.Assert(false); } } // // Read from the btree // IBtreeValue seekValue1 = tree.SeekAsync(key1, CancellationToken.None).Result; IBtreeValue seekValue2 = tree.SeekAsync(key2, CancellationToken.None).Result; byte[] seekValue2InBytes = seekValue2.Bytes; if (null != seekValue2InBytes) { LogHelper.Log("Seek value {0}", seekValue2InBytes.Length); throw new InvalidOperationException(); } // // Delete from the btree // Tuple <bool, IRedoUndoInformation> infoRedoUndoDelete1 = tree.DeleteAsync(key1, sequenceNumber++, CancellationToken.None).Result; if (3 != infoRedoUndoDelete1.Item2.Redo.Count()) { LogHelper.Log("Delete redo buffers {0}", infoRedoUndoDelete1.Item2.Redo.Count()); throw new InvalidOperationException(); } if (3 != infoRedoUndoDelete1.Item2.Undo.Count()) { LogHelper.Log("Delete undo buffers {0}", infoRedoUndoDelete1.Item2.Undo.Count()); throw new InvalidOperationException(); } Tuple <bool, IRedoUndoInformation> infoRedoUndoDelete2 = tree.DeleteAsync(key2, sequenceNumber++, CancellationToken.None).Result; if (3 != infoRedoUndoDelete2.Item2.Redo.Count()) { LogHelper.Log("Delete redo buffers {0}", infoRedoUndoDelete2.Item2.Redo.Count()); throw new InvalidOperationException(); } if (3 != infoRedoUndoDelete2.Item2.Undo.Count()) { LogHelper.Log("Delete undo buffers {0}", infoRedoUndoDelete2.Item2.Undo.Count()); throw new InvalidOperationException(); } IBtreeOperation deleteOperation11 = treeApply.ApplyWithOutputAsync(sequenceNumber, infoRedoUndoDelete1.Item2.Redo, true, CancellationToken.None).Result; IBtreeOperation deleteOperation12 = treeApply.ApplyWithOutputAsync(sequenceNumber, infoRedoUndoDelete1.Item2.Redo, false, CancellationToken.None).Result; // // Delete from the btree // try { tree.DeleteAsync(key1, sequenceNumber++, CancellationToken.None).Wait(); Debug.Assert(false); } catch (AggregateException e) { if (!(e.InnerException is KeyNotFoundException)) { Debug.Assert(false); } } // // Read from the btree // try { tree.SeekAsync(key1, CancellationToken.None).Wait(); Debug.Assert(false); } catch (AggregateException e) { if (!(e.InnerException is KeyNotFoundException)) { Debug.Assert(false); } } // // Close the btree // LogHelper.Log("Begin close btree"); tree.CloseAsync(true, CancellationToken.None).Wait(); treeApply.CloseAsync(true, CancellationToken.None).Wait(); LogHelper.Log("End close btree"); }, "OpenCloseInsertSeekDeleteGuidKeyStringValue"); }
public void OpenCloseInsertGuidKeyStringValue() { Utility.WrapNativeSyncInvokeInMTA(() => { Uri owner = new Uri("fabric://test/btree"); LogHelper.Log("Begin construct btree"); Btree <Guid, string, GuidKeyBitConverter, UnicodeStringValueBitConverter> tree = new Btree <Guid, string, GuidKeyBitConverter, UnicodeStringValueBitConverter>(); LogHelper.Log("End construct btree"); // // Key configuration // LogHelper.Log("Start create key description"); GuidKeyComparison guidKeyComparison = new GuidKeyComparison(); LogHelper.Log("End create key description"); // // Storage configuration // LogHelper.Log("Start create storage description"); BtreeStorageConfigurationDescription storageDescription = new BtreeStorageConfigurationDescription(); storageDescription.IsVolatile = true; storageDescription.MaximumMemoryInMB = 1024; storageDescription.MaximumPageSizeInKB = 4; storageDescription.MaximumStorageInMB = 0; storageDescription.RetriesBeforeTimeout = 100; storageDescription.StoreDataInline = true; LogHelper.Log("End create key description"); // // Btree configuration // LogHelper.Log("Start create btree description"); BtreeConfigurationDescription btreeConfig = new BtreeConfigurationDescription(); btreeConfig.KeyComparison = guidKeyComparison.KeyComparison; btreeConfig.StorageConfiguration = storageDescription; btreeConfig.PartitionId = Guid.NewGuid(); btreeConfig.ReplicaId = 130083631515748206; LogHelper.Log("End create btree description"); // // Open the btree // LogHelper.Log("Begin open btree"); tree.OpenAsync(btreeConfig, false, CancellationToken.None).Wait(); LogHelper.Log("End open btree"); // // Insert into the btree // for (int sequenceNumber = 0; sequenceNumber < 16; sequenceNumber++) { BtreeKey <Guid, GuidKeyBitConverter> key = new BtreeKey <Guid, GuidKeyBitConverter>(Guid.NewGuid()); BtreeValue <string, UnicodeStringValueBitConverter> value = new BtreeValue <string, UnicodeStringValueBitConverter>(sequenceNumber.ToString()); IRedoUndoInformation infoRedoUndo = tree.InsertAsync(key, value, sequenceNumber, CancellationToken.None).Result; } // // Close the btree // LogHelper.Log("Begin close btree"); tree.CloseAsync(true, CancellationToken.None).Wait(); LogHelper.Log("End close btree"); }, "OpenCloseInsertGuidKeyStringValue"); }