示例#1
0
        public AzureTableChasmRepo(CloudStorageAccount storageAccount, IChasmSerializer serializer, CompressionLevel compressionLevel, int maxDop)
            : base(serializer, compressionLevel, maxDop)
        {
            if (storageAccount == null)
            {
                throw new ArgumentNullException(nameof(storageAccount));
            }

            var client = storageAccount.CreateCloudTableClient();

            // Refs
            _refsTable = new Lazy <CloudTable>(() =>
            {
                const string table = "refs";
                var tr             = client.GetTableReference(table);

                tr.CreateIfNotExistsAsync().Wait();

                return(tr);
            }, LazyThreadSafetyMode.PublicationOnly);

            // Objects
            _objectsTable = new Lazy <CloudTable>(() =>
            {
                const string container = "objects";
                var tr = client.GetTableReference(container);

                tr.CreateIfNotExistsAsync().Wait();

                return(tr);
            }, LazyThreadSafetyMode.PublicationOnly);
        }
示例#2
0
        public AzureBlobChasmRepo(CloudStorageAccount storageAccount, IChasmSerializer serializer, CompressionLevel compressionLevel, int maxDop)
            : base(serializer, compressionLevel, maxDop)
        {
            if (storageAccount == null)
            {
                throw new ArgumentNullException(nameof(storageAccount));
            }

            var client = storageAccount.CreateCloudBlobClient();

            client.DefaultRequestOptions.ParallelOperationThreadCount = 4; // Default is 1

            // Refs
            _refsContainer = new Lazy <CloudBlobContainer>(() =>
            {
                const string container = "refs";
                var tr = client.GetContainerReference(container);

                tr.CreateIfNotExistsAsync().Wait();

                return(tr);
            }, LazyThreadSafetyMode.PublicationOnly);

            // Objects
            _objectsContainer = new Lazy <CloudBlobContainer>(() =>
            {
                const string container = "objects";
                var tr = client.GetContainerReference(container);

                tr.CreateIfNotExistsAsync().Wait();

                return(tr);
            }, LazyThreadSafetyMode.PublicationOnly);
        }
示例#3
0
        public static void ChasmSerializer_Roundtrip_TreeNodeMap_2_Nodes(IChasmSerializer ser)
        {
            var expected = new TreeNodeMap(s_node1, s_node2);

            using (IMemoryOwner <byte> owner = ser.Serialize(expected))
            {
                TreeNodeMap actual = ser.DeserializeTree(owner.Memory.Span);
                Assert.Equal(expected, actual);
            }
        }
示例#4
0
        public static void ChasmSerializer_Roundtrip_TreeNodeMap_Default(IChasmSerializer ser)
        {
            TreeNodeMap expected = default;

            using (IMemoryOwner <byte> owner = ser.Serialize(expected))
            {
                TreeNodeMap actual = ser.DeserializeTree(owner.Memory.Span);
                Assert.Equal(expected, actual);
            }
        }
示例#5
0
        public static void ChasmSerializer_Roundtrip_TreeNodeMap_Empty_Array(IChasmSerializer ser)
        {
            var expected = new TreeNodeMap();

            using (var buf = ser.Serialize(expected))
            {
                var actual = ser.DeserializeTree(buf.Result);
                Assert.Equal(expected, actual);
            }
        }
示例#6
0
        public static void ChasmSerializer_Roundtrip_TreeNodeList_Default(IChasmSerializer ser)
        {
            TreeNodeList expected = default;

            using (var buf = ser.Serialize(expected))
            {
                var actual = ser.DeserializeTree(buf.Result);
                Assert.Equal(expected, actual);
            }
        }
示例#7
0
        public static void ChasmSerializer_Roundtrip_TreeNodeList_2_Nodes(IChasmSerializer ser)
        {
            var expected = new TreeNodeList(Node1, Node2);

            using (var buf = ser.Serialize(expected))
            {
                var actual = ser.DeserializeTree(buf.Result);
                Assert.Equal(expected, actual);
            }
        }
示例#8
0
        public static void ChasmSerializer_Roundtrip_CommitId_Default(IChasmSerializer ser)
        {
            var expected = CommitId.Empty;

            using (var buf = ser.Serialize(expected))
            {
                var actual = ser.DeserializeCommitId(buf.Result);
                Assert.Equal(expected, actual);
            }
        }
示例#9
0
        public static void ChasmSerializer_Roundtrip_CommitId(IChasmSerializer ser)
        {
            var expected = new CommitId(Sha1.Hash("abc"));

            using (var buf = ser.Serialize(expected))
            {
                var actual = ser.DeserializeCommitId(buf.Result);
                Assert.Equal(expected, actual);
            }
        }
示例#10
0
        public static void ChasmSerializer_WriteRead_EmptyTreeNodeMap(IChasmSerializer ser)
        {
            var expected = new TreeNodeMap(new TreeNode[0]);

            using (IMemoryOwner <byte> owner = ser.Serialize(expected))
            {
                TreeNodeMap actual = ser.DeserializeTree(owner.Memory.Span);

                Assert.Equal(expected, actual);
            }
        }
示例#11
0
        public static void ChasmSerializer_WriteRead_EmptyTreeNodeList(IChasmSerializer ser)
        {
            var expected = new TreeNodeList(new TreeNode[0]);

            using (var seg = ser.Serialize(expected))
            {
                var actual = ser.DeserializeTree(seg.Result);

                Assert.Equal(expected, actual);
            }
        }
示例#12
0
        public HybridChasmRepo(IChasmRepository repository, IChasmSerializer serializer, CompressionLevel compressionLevel, int maxDop)
            : base(serializer, compressionLevel, maxDop)
        {
            if (repository == null)
            {
                throw new ArgumentNullException(nameof(repository));
            }

            Chain = new IChasmRepository[1] {
                repository
            };
        }
示例#13
0
        public DiskChasmRepo(string rootFolder, IChasmSerializer serializer, CompressionLevel compressionLevel, int maxDop)
            : base(serializer, compressionLevel, maxDop)
        {
            if (string.IsNullOrWhiteSpace(rootFolder) || rootFolder.Length <= 2)
            {
                throw new ArgumentNullException(nameof(rootFolder));                                                                  // "C:\" is shortest permitted path
            }
            if (rootFolder[rootFolder.Length - 1] != Path.DirectorySeparatorChar)
            {
                throw new ArgumentException("Path must end with " + Path.DirectorySeparatorChar, nameof(rootFolder));
            }
            var rootPath = Path.GetFullPath(rootFolder);

            if (rootPath != rootFolder)
            {
                throw new ArgumentException("Path must be fully qualified", nameof(rootFolder));
            }

            // Root
            {
                if (!Directory.Exists(rootPath))
                {
                    Directory.CreateDirectory(rootPath);
                }
            }

            // Refs
            {
                const string container = "refs";
                var          path      = Path.Combine(rootPath, container) + Path.DirectorySeparatorChar;

                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                _refsContainer = path;
            }

            // Objects
            {
                const string container = "objects";
                var          path      = Path.Combine(rootPath, container) + Path.DirectorySeparatorChar;

                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                _objectsContainer = path;
            }
        }
示例#14
0
        public static void ChasmSerializer_WriteRead_TreeNodeList(IChasmSerializer ser)
        {
            var node0    = new TreeNode("a", NodeKind.Blob, Sha1.Hash("abc"));
            var node1    = new TreeNode("b", NodeKind.Tree, Sha1.Hash("def"));
            var node2    = new TreeNode("c", NodeKind.Tree, Sha1.Hash("hij"));
            var expected = new TreeNodeList(node0, node1, node2);

            using (var seg = ser.Serialize(expected))
            {
                var actual = ser.DeserializeTree(seg.Result);

                Assert.Equal(expected, actual);
            }
        }
示例#15
0
        public static void ChasmSerializer_WriteRead_TreeNodeMap(IChasmSerializer ser)
        {
            var node0    = new TreeNode("a", NodeKind.Blob, s_hasher.HashData("abc"));
            var node1    = new TreeNode("b", NodeKind.Tree, s_hasher.HashData("def"));
            var node2    = new TreeNode("c", NodeKind.Tree, s_hasher.HashData("hij"));
            var expected = new TreeNodeMap(node0, node1, node2);

            using (IMemoryOwner <byte> owner = ser.Serialize(expected))
            {
                TreeNodeMap actual = ser.DeserializeTree(owner.Memory.Span);

                Assert.Equal(expected, actual);
            }
        }
示例#16
0
        protected ChasmRepository(IChasmSerializer serializer, CompressionLevel compressionLevel, int maxDop)
        {
            if (!Enum.IsDefined(typeof(CompressionLevel), compressionLevel))
            {
                throw new ArgumentOutOfRangeException(nameof(compressionLevel));
            }
            if (maxDop < -1 || maxDop == 0)
            {
                throw new ArgumentOutOfRangeException(nameof(maxDop));
            }

            Serializer       = serializer ?? throw new ArgumentNullException(nameof(serializer));
            CompressionLevel = compressionLevel;
            MaxDop           = maxDop;
        }
示例#17
0
        public static AzureTableChasmRepo Create(string connectionString, IChasmSerializer serializer, CompressionLevel compressionLevel)
        {
            if (string.IsNullOrWhiteSpace(connectionString))
            {
                throw new ArgumentException(nameof(connectionString));
            }
            if (serializer == null)
            {
                throw new ArgumentNullException(nameof(serializer));
            }

            var storageAccount = CloudStorageAccount.Parse(connectionString);
            var repo           = new AzureTableChasmRepo(storageAccount, serializer, compressionLevel);

            return(repo);
        }
示例#18
0
        public DiskChasmRepo(string rootFolder, IChasmSerializer serializer)
            : base(serializer)
        {
            if (string.IsNullOrWhiteSpace(rootFolder) || rootFolder.Length < 3)
            {
                throw new ArgumentNullException(nameof(rootFolder));                                                                 // "C:\" is shortest permitted path
            }
            RootPath = rootFolder.EndsWith(Path.DirectorySeparatorChar)
                ? Path.GetFullPath(rootFolder)
                : Path.GetFullPath(rootFolder + Path.DirectorySeparatorChar);

            // Root
            {
                if (!Directory.Exists(RootPath))
                {
                    Directory.CreateDirectory(RootPath);
                }
            }

            // Objects
            {
                const string container = "objects";
                string       path      = Path.Combine(RootPath, container);

                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                _objectsContainer = path;
            }

            // Refs
            {
                const string container = "refs";
                string       path      = Path.Combine(RootPath, container);

                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                _refsContainer = path;
            }
        }
示例#19
0
        public HybridChasmRepo(IChasmRepository[] chain, IChasmSerializer serializer, CompressionLevel compressionLevel, int maxDop)
            : base(serializer, compressionLevel, maxDop)
        {
            if (chain == null || chain.Length == 0)
            {
                throw new ArgumentNullException(nameof(chain));
            }

            for (var i = 0; i < chain.Length; i++)
            {
                if (chain[i] == null)
                {
                    throw new ArgumentNullException(nameof(chain));
                }
            }

            Chain = chain;
        }
示例#20
0
 public MockChasmRepository(IChasmSerializer serializer, CompressionLevel compressionLevel, int maxDop)
     : base(serializer, compressionLevel, maxDop)
 {
 }
示例#21
0
 public AzureTableChasmRepo(CloudStorageAccount storageAccount, IChasmSerializer serializer)
     : this(storageAccount, serializer, CompressionLevel.Optimal)
 {
 }
示例#22
0
 public AzureTableChasmRepo(CloudStorageAccount storageAccount, IChasmSerializer serializer, CompressionLevel compressionLevel)
     : this(storageAccount, serializer, compressionLevel, -1)
 {
 }
示例#23
0
 public MockChasmRepository(IChasmSerializer serializer)
     : base(serializer)
 {
 }
示例#24
0
 public DiskChasmRepo(string rootFolder, IChasmSerializer serializer, CompressionLevel compressionLevel)
     : this(rootFolder, serializer, compressionLevel, -1)
 {
 }
示例#25
0
 public DiskChasmRepo(string rootFolder, IChasmSerializer serializer)
     : this(rootFolder, serializer, CompressionLevel.Optimal)
 {
 }
示例#26
0
 public static void ChasmSerializer_Roundtrip_Commit_Utc(IChasmSerializer ser)
 {
     var expected = new Commit(null, default, new Audit("bob", Utc1), new Audit("mary", Utc1), null);
示例#27
0
 public static void ChasmSerializer_Roundtrip_Commit_Parents_Null(IChasmSerializer ser)
 {
     // Force Commit to be non-default
     var expected = new Commit(new CommitId?(), default, default, default, "force");
示例#28
0
 public static void ChasmSerializer_Roundtrip_Commit_TreeId_Empty(IChasmSerializer ser)
 {
     var expected = new Commit(new CommitId?(), default, default, default, null);
示例#29
0
        public HybridChasmRepo(IChasmRepository repository1, IChasmRepository repository2, IChasmRepository repository3, IChasmSerializer serializer, CompressionLevel compressionLevel, int maxDop)
            : base(serializer, compressionLevel, maxDop)
        {
            if (repository1 == null)
            {
                throw new ArgumentNullException(nameof(repository1));
            }
            if (repository2 == null)
            {
                throw new ArgumentNullException(nameof(repository2));
            }
            if (repository3 == null)
            {
                throw new ArgumentNullException(nameof(repository3));
            }

            Chain = new IChasmRepository[3] {
                repository1, repository2, repository3
            };
        }
示例#30
0
        public static void ChasmSerializer_Roundtrip_Commit_Message_Null(IChasmSerializer ser)
        {
            // Force Commit to be non-default
            var force = new Audit("bob", DateTimeOffset.Now);

            var expected = new Commit(new CommitId?(), default, force, default, null);