public void Should_create_and_clear_and_delete_collection() { Database.DeleteTestCollection(Database.TestDocumentCollectionName); ArangoDatabase db = Database.GetTestDatabase(); // set collection data ArangoCollection collection = new ArangoCollection(); collection.Name = Database.TestDocumentCollectionName; // create collection in database db.Collection.Create(collection); // clear collection data var isCleared = db.Collection.Clear(Database.TestDocumentCollectionName); Assert.AreEqual(true, isCleared); // delete collection from database bool isDeleted = db.Collection.Delete(collection.Name); // check if the collection was deleted from database Assert.AreEqual(true, isDeleted); }
public void Should_create_sharded_collection() { var db = Database.GetTestDatabase(); if (!db.Server.Role().IsCluster()) { // do not execute this test in non-cluster mode return; } Database.DeleteTestCollection(Database.TestDocumentCollectionName); // set collection data var collection = new ArangoCollection(); collection.Name = Database.TestDocumentCollectionName; collection.NumberOfShards = 5; // create collection in database db.Collection.Create(collection); // get collection from database ArangoCollection returnedCollection = db.Collection.Properties(Database.TestDocumentCollectionName); // get collection properties from database Assert.AreEqual(collection.Id, returnedCollection.Id); Assert.AreEqual(collection.Name, returnedCollection.Name); Assert.AreEqual(false, returnedCollection.IsVolatile); Assert.AreEqual(false, returnedCollection.IsSystem); Assert.AreEqual(5, returnedCollection.NumberOfShards); }
public void Should_create_and_get_and_delete_collection() { Database.DeleteTestCollection(Database.TestDocumentCollectionName); ArangoDatabase db = Database.GetTestDatabase(); // set collection data ArangoCollection collection = new ArangoCollection(); collection.Name = Database.TestDocumentCollectionName; // create collection in database db.Collection.Create(collection); // get collection from database ArangoCollection returnedCollection = db.Collection.Get(Database.TestDocumentCollectionName); // check collection data retrieved from server Assert.AreEqual(collection.Id, returnedCollection.Id); Assert.AreEqual(collection.Name, returnedCollection.Name); Assert.AreEqual(collection.Type, returnedCollection.Type); Assert.AreEqual(collection.Status, returnedCollection.Status); // delete collection from database bool isDeleted = db.Collection.Delete(collection.Name); // check if the collection was deleted from database Assert.AreEqual(true, isDeleted); }
public void Should_create_and_delete_collection() { Database.DeleteTestCollection(Database.TestEdgeCollectionName); ArangoDatabase db = Database.GetTestDatabase(); // set collection data ArangoCollection collection = new ArangoCollection(); collection.Name = Database.TestEdgeCollectionName; collection.Type = ArangoCollectionType.Edge; collection.WaitForSync = true; // create collection in database db.Collection.Create(collection); // check collection data retrieved from server Assert.AreEqual(false, string.IsNullOrEmpty(collection.Id)); Assert.AreEqual(Database.TestEdgeCollectionName, collection.Name); Assert.AreEqual(ArangoCollectionType.Edge, collection.Type); Assert.AreEqual(ArangoCollectionStatus.Loaded, collection.Status); Assert.AreEqual(true, collection.WaitForSync); Assert.AreEqual(false, collection.IsSystem); Assert.AreEqual(false, collection.IsVolatile); // delete collection from database bool isDeleted = db.Collection.Delete(collection.Name); // check if the collection was deleted from database Assert.AreEqual(true, isDeleted); }
internal ArangoCollection Get(string name) { var request = new Request(RequestType.Collection, HttpMethod.Get); request.RelativeUri = string.Join("/", _apiUri, name); var response = _connection.Process(request); var collection = new ArangoCollection(); switch (response.StatusCode) { case HttpStatusCode.OK: collection.Id = response.Document.String("id"); collection.Name = response.Document.String("name"); collection.Status = response.Document.Enum<ArangoCollectionStatus>("status"); collection.Type = response.Document.Enum<ArangoCollectionType>("type"); break; case HttpStatusCode.NotFound: collection = null; break; default: if (response.IsException) { throw new ArangoException( response.StatusCode, response.Document.String("driverErrorMessage"), response.Document.String("driverExceptionMessage"), response.Document.Object<Exception>("driverInnerException") ); } break; } return collection; }
public async Task CreateAsync(ArangoHandle database, ArangoCollection collection, CancellationToken cancellationToken = default) { await SendAsync <ArangoVoid>(HttpMethod.Post, ApiPath(database, "collection"), collection, cancellationToken : cancellationToken); }
public async Task CreateCollectionAsync(ArangoHandle database, ArangoCollection collection, CancellationToken cancellationToken = default) { await SendAsync <JObject>(HttpMethod.Post, $"{Server}/_db/{DbName(database)}/_api/collection", JsonConvert.SerializeObject(collection, JsonSerializerSettings), cancellationToken : cancellationToken); }
public async Task CreateAsync(ArangoHandle database, ArangoCollection collection, CancellationToken cancellationToken = default) { await SendAsync <JObject>(HttpMethod.Post, ApiPath(database, "collection"), JsonConvert.SerializeObject(collection, ArangoContext.JsonSerializerSettings), cancellationToken : cancellationToken); }
internal ArangoCollection Properties(string name) { var request = new Request(RequestType.Collection, HttpMethod.Get); request.RelativeUri = string.Join("/", _apiUri, name, "properties"); var response = _connection.Process(request); var collection = new ArangoCollection(); switch (response.StatusCode) { case HttpStatusCode.OK: collection.Id = response.Document.String("id"); collection.Name = response.Document.String("name"); collection.Status = response.Document.Enum <ArangoCollectionStatus>("status"); collection.Type = response.Document.Enum <ArangoCollectionType>("type"); collection.WaitForSync = response.Document.Bool("waitForSync"); collection.IsSystem = response.Document.Bool("isSystem"); collection.IsVolatile = response.Document.Bool("isVolatile"); collection.JournalSize = response.Document.Int("journalSize"); if (response.Document.Has("numberOfShards")) { collection.NumberOfShards = response.Document.Int("numberOfShards"); } if (response.Document.Has("shardKeys")) { collection.ShardKeys = (List <string>)response.Document.List <string>("shardKeys"); } break; case HttpStatusCode.NotFound: collection = null; break; default: if (response.IsException) { throw new ArangoException( response.StatusCode, response.Document.String("driverErrorMessage"), response.Document.String("driverExceptionMessage"), response.Document.Object <Exception>("driverInnerException") ); } break; } return(collection); }
public static void CreateTestCollection(string collectionName, ArangoCollectionType collectionType = ArangoCollectionType.Document) { var db = GetTestDatabase(); if (db.Collection.Get(collectionName) != null) { // delet collection if it exists db.Collection.Delete(collectionName); } // create new test collection var collection = new ArangoCollection(); collection.Name = collectionName; collection.Type = collectionType; db.Collection.Create(collection); }
/// <summary> /// Create a collection based on the given ArangoCollection /// </summary> /// <typeparam name="T"></typeparam> /// <param name="collection"></param> /// <returns></returns> public async Task <CollectionResult> CreateCollection <T>(ArangoCollection collection) { Payload payload = new Payload() { Content = JsonConvert.SerializeObject(collection, databaseSettings.JsonSettings), Method = HttpMethod.Post, Path = string.Format("_api/collection") }; var result = await GetResultAsync(payload); if (result == null) { return(default(CollectionResult)); } var json = JsonConvert.DeserializeObject <CollectionResult>(result.Content); return(json); }
public void Shoud_generate_and_execute_query() { String collectionName = "UnitTestCollection"; ArangoCollection myCollection = new ArangoCollection(); myCollection.Name = collectionName; db.Collection.Create(myCollection); Document myDocument; for (int i = 0; i < 100; i++) { myDocument = new Document(); myDocument.Add("num", i); db.Document.Create(collectionName, myDocument, true, false); } var query = "FOR docs IN UnitTestCollection return docs"; var documents = db.Query.Aql(query).ToList(); Assert.AreEqual(documents.Count(), 100); }
public void Should_create_autoincrement_collection() { var db = Database.GetTestDatabase(); if (db.Server.Role().IsCluster()) { // do not execute this test on a coordinator return; } Database.DeleteTestCollection(Database.TestDocumentCollectionName); // set collection data var collection = new ArangoCollection(); collection.Name = Database.TestDocumentCollectionName; collection.KeyOptions = new ArangoCollectionKeyOptions(); collection.KeyOptions.GeneratorType = ArangoKeyGeneratorType.Autoincrement; // create collection in database db.Collection.Create(collection); // create document var document1 = new Document() .String("foo", "foo string value"); db.Document.Create(Database.TestDocumentCollectionName, document1); // check if the created document key starts with number 1 Assert.AreEqual("1", document1.String("_key")); // create another document var document2 = new Document() .String("foo", "foo string value"); db.Document.Create(Database.TestDocumentCollectionName, document2); // check if the created document key is autoincremented to 2 Assert.AreEqual("2", document2.String("_key")); }
public async Task Migrate2X() { var migrator = new ArangoMigrator(Arango); await migrator.ApplyStructureAsync("test", new ArangoStructure { Collections = new List <ArangoCollectionIndices> { new () { Collection = new ArangoCollection { Name = "MarketData", KeyOptions = new ArangoKeyOptions { Type = ArangoKeyType.Padded } }, Indices = new List <ArangoIndex> { new () { Name = "IDX_Symbol", Type = ArangoIndexType.Hash, Fields = new List <string> { "S" } }, new () { Name = "IDX_Time", Type = ArangoIndexType.Skiplist, Fields = new List <string> { "T" } } } } } });
internal ArangoCollection Get(string name) { var request = new Request(RequestType.Collection, HttpMethod.Get); request.RelativeUri = string.Join("/", _apiUri, name); var response = _connection.Process(request); var collection = new ArangoCollection(); switch (response.StatusCode) { case HttpStatusCode.OK: collection.Id = response.Document.String("id"); collection.Name = response.Document.String("name"); collection.Status = response.Document.Enum <ArangoCollectionStatus>("status"); collection.Type = response.Document.Enum <ArangoCollectionType>("type"); break; case HttpStatusCode.NotFound: collection = null; break; default: if (response.IsException) { throw new ArangoException( response.StatusCode, response.Document.String("driverErrorMessage"), response.Document.String("driverExceptionMessage"), response.Document.Object <Exception>("driverInnerException") ); } break; } return(collection); }
public void Should_create_synchronous_collection() { Database.DeleteTestCollection(Database.TestDocumentCollectionName); var db = Database.GetTestDatabase(); // set collection data var collection = new ArangoCollection(); collection.Name = Database.TestDocumentCollectionName; collection.WaitForSync = true; // create collection in database db.Collection.Create(collection); // get collection from database ArangoCollection returnedCollection = db.Collection.Properties(Database.TestDocumentCollectionName); // get collection properties from database Assert.AreEqual(collection.Id, returnedCollection.Id); Assert.AreEqual(collection.Name, returnedCollection.Name); Assert.AreEqual(true, returnedCollection.WaitForSync); Assert.AreEqual(false, returnedCollection.IsVolatile); }
internal void Post(ArangoCollection collection) { var request = new Request(RequestType.Collection, HttpMethod.Post); request.RelativeUri = _apiUri; var document = new Document(); // set collection name document.String("name", collection.Name); // (optional, default: 2) set type if (collection.Type != 0) { document.Enum("type", collection.Type); } // (optional, default: false) set waitForSync if (collection.WaitForSync) { document.Bool("waitForSync", collection.WaitForSync); } // (optional, default: arangodb config) set journalSize if (collection.JournalSize > 0) { document.Int("journalSize", collection.JournalSize); } // (optional, default: false) set isSystem if (collection.IsSystem) { document.Bool("isSystem", collection.IsSystem); } // (optional, default: false) set isVolatile if (collection.IsVolatile) { document.Bool("isVolatile", collection.IsVolatile); } if (collection.NumberOfShards != null) { document.Int("numberOfShards", (int)collection.NumberOfShards); } if (collection.ShardKeys != null) { document.List("shardKeys", collection.ShardKeys); } // (optional) set keyOptions if (collection.KeyOptions != null) { if (collection.KeyOptions.GeneratorType != 0) { document.String("keyOptions.type", collection.KeyOptions.GeneratorType.ToString().ToLower()); if (collection.KeyOptions.GeneratorType == ArangoKeyGeneratorType.Autoincrement) { if (collection.KeyOptions.Increment > 0) { document.Int("keyOptions.increment", collection.KeyOptions.Increment); } if (collection.KeyOptions.Offset > 0) { document.Int("keyOptions.offset", collection.KeyOptions.Offset); } } } if (collection.KeyOptions.AllowUserKeys) { document.Bool("keyOptions.allowUserKeys", collection.KeyOptions.AllowUserKeys); } } request.Body = Document.Serialize(document); var response = _connection.Process(request); switch (response.StatusCode) { case HttpStatusCode.OK: collection.Id = response.Document.String("id"); collection.Name = response.Document.String("name"); collection.Status = response.Document.Enum <ArangoCollectionStatus>("status"); collection.Type = response.Document.Enum <ArangoCollectionType>("type"); collection.WaitForSync = response.Document.Bool("waitForSync"); collection.IsVolatile = response.Document.Bool("isVolatile"); collection.IsSystem = response.Document.Bool("isSystem"); break; default: if (response.IsException) { throw new ArangoException( response.StatusCode, response.Document.String("driverErrorMessage"), response.Document.String("driverExceptionMessage"), response.Document.Object <Exception>("driverInnerException") ); } break; } }
internal ArangoCollection Properties(string name) { var request = new Request(RequestType.Collection, HttpMethod.Get); request.RelativeUri = string.Join("/", _apiUri, name, "properties"); var response = _connection.Process(request); var collection = new ArangoCollection(); switch (response.StatusCode) { case HttpStatusCode.OK: collection.Id = response.Document.String("id"); collection.Name = response.Document.String("name"); collection.Status = response.Document.Enum<ArangoCollectionStatus>("status"); collection.Type = response.Document.Enum<ArangoCollectionType>("type"); collection.WaitForSync = response.Document.Bool("waitForSync"); collection.IsSystem = response.Document.Bool("isSystem"); collection.IsVolatile = response.Document.Bool("isVolatile"); collection.JournalSize = response.Document.Int("journalSize"); if (response.Document.Has("numberOfShards")) { collection.NumberOfShards = response.Document.Int("numberOfShards"); } if (response.Document.Has("shardKeys")) { collection.ShardKeys = (List<string>) response.Document.List<string>("shardKeys"); } break; case HttpStatusCode.NotFound: collection = null; break; default: if (response.IsException) { throw new ArangoException( response.StatusCode, response.Document.String("driverErrorMessage"), response.Document.String("driverExceptionMessage"), response.Document.Object<Exception>("driverInnerException") ); } break; } return collection; }
internal void Post(ArangoCollection collection) { var request = new Request(RequestType.Collection, HttpMethod.Post); request.RelativeUri = _apiUri; var document = new Document(); // set collection name document.String("name", collection.Name); // (optional, default: 2) set type if (collection.Type != 0) { document.Enum("type", collection.Type); } // (optional, default: false) set waitForSync if (collection.WaitForSync) { document.Bool("waitForSync", collection.WaitForSync); } // (optional, default: arangodb config) set journalSize if (collection.JournalSize > 0) { document.Int("journalSize", collection.JournalSize); } // (optional, default: false) set isSystem if (collection.IsSystem) { document.Bool("isSystem", collection.IsSystem); } // (optional, default: false) set isVolatile if (collection.IsVolatile) { document.Bool("isVolatile", collection.IsVolatile); } if (collection.NumberOfShards != null) { document.Int("numberOfShards", (int) collection.NumberOfShards); } if (collection.ShardKeys != null) { document.List("shardKeys", collection.ShardKeys); } // (optional) set keyOptions if (collection.KeyOptions != null) { if (collection.KeyOptions.GeneratorType != 0) { document.String("keyOptions.type", collection.KeyOptions.GeneratorType.ToString().ToLower()); if (collection.KeyOptions.GeneratorType == ArangoKeyGeneratorType.Autoincrement) { if (collection.KeyOptions.Increment > 0) { document.Int("keyOptions.increment", collection.KeyOptions.Increment); } if (collection.KeyOptions.Offset > 0) { document.Int("keyOptions.offset", collection.KeyOptions.Offset); } } } if (collection.KeyOptions.AllowUserKeys) { document.Bool("keyOptions.allowUserKeys", collection.KeyOptions.AllowUserKeys); } } request.Body = Document.Serialize(document); var response = _connection.Process(request); switch (response.StatusCode) { case HttpStatusCode.OK: collection.Id = response.Document.String("id"); collection.Name = response.Document.String("name"); collection.Status = response.Document.Enum<ArangoCollectionStatus>("status"); collection.Type = response.Document.Enum<ArangoCollectionType>("type"); collection.WaitForSync = response.Document.Bool("waitForSync"); collection.IsVolatile = response.Document.Bool("isVolatile"); collection.IsSystem = response.Document.Bool("isSystem"); break; default: if (response.IsException) { throw new ArangoException( response.StatusCode, response.Document.String("driverErrorMessage"), response.Document.String("driverExceptionMessage"), response.Document.Object<Exception>("driverInnerException") ); } break; } }