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); }
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); }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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 }; }
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; } }
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); } }
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); } }
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; }
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); }
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; } }
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; }
public MockChasmRepository(IChasmSerializer serializer, CompressionLevel compressionLevel, int maxDop) : base(serializer, compressionLevel, maxDop) { }
public AzureTableChasmRepo(CloudStorageAccount storageAccount, IChasmSerializer serializer) : this(storageAccount, serializer, CompressionLevel.Optimal) { }
public AzureTableChasmRepo(CloudStorageAccount storageAccount, IChasmSerializer serializer, CompressionLevel compressionLevel) : this(storageAccount, serializer, compressionLevel, -1) { }
public MockChasmRepository(IChasmSerializer serializer) : base(serializer) { }
public DiskChasmRepo(string rootFolder, IChasmSerializer serializer, CompressionLevel compressionLevel) : this(rootFolder, serializer, compressionLevel, -1) { }
public DiskChasmRepo(string rootFolder, IChasmSerializer serializer) : this(rootFolder, serializer, CompressionLevel.Optimal) { }
public static void ChasmSerializer_Roundtrip_Commit_Utc(IChasmSerializer ser) { var expected = new Commit(null, default, new Audit("bob", Utc1), new Audit("mary", Utc1), null);
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");
public static void ChasmSerializer_Roundtrip_Commit_TreeId_Empty(IChasmSerializer ser) { var expected = new Commit(new CommitId?(), default, default, default, null);
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 }; }
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);