public static void Main() { IDseCluster cluster = DseCluster.Builder(). AddContactPoint("127.0.0.1"). WithGraphOptions(new GraphOptions().SetName("killrvideo")). Build(); IDseSession session = cluster.Connect(); var killr = DseGraph.Traversal(session); PrintHeader("Actors for Young Guns", "killr.Movies(\"Young Guns\").Actors().Values(\"name\")"); var results = killr.Movies("Young Guns").Actors().Values <string>("name").ToList(); PrintItems(results); PrintHeader("Ratings Distribution by Age for Young Guns", "killr.Movies(\"Young Guns\").Ratings().DistributionForAges(18, 40)"); IDictionary <string, long> ratingsByAge = killr.Movies("Young Guns").Ratings().DistributionForAges(18, 40).Next(); var pairs = String.Join(", ", ratingsByAge.Select(kvp => kvp.Key + "=" + kvp.Value.ToString())); Console.WriteLine($"[{pairs}]"); PrintHeader("Failed Validation", "killr.Movies(\"Young Guns\").Ratings().DistributionForAges(17,40)"); try { killr.Movies("Young Guns").Ratings().DistributionForAges(17, 40).Next(); } catch (ArgumentException ae) { Console.WriteLine($"Caught ArgumentException: {ae.Message}"); } PrintHeader("Five Recommendations for u460", "killr.Users(\"u460\").Recommend(5, 7).Values(KEY_TITLE)"); results = killr.Users("u460").Recommend(5, 7).Values <string>(KeyTitle).ToList(); PrintItems(results); PrintHeader("Five Recommendations for u460 that are comedies", "killr.Users(\"u460\").Recommend(5, 7, Genre(COMEDY)).Values(KEY_TITLE)"); results = killr.Users("u460").Recommend(5, 7, Genre(Comedy)).Values <string>(KeyTitle).ToList(); PrintItems(results); PrintHeader("Five Recommendations for u460 that use larger actor sampling and are comedies", "killr.users(\"u460\").recommend(5, 7, genre(COMEDY)).values(KEY_TITLE)"); results = killr.Users("u460").Recommend(5, 7, LargeSample, Genre(Comedy)).Values <string>(KeyTitle).ToList(); PrintItems(results); PrintHeader("Include some additional graph statistics about Young Guns", "killr.movies(\"Young Guns\").enrich(IN_DEGREE, OUT_DEGREE)"); IDictionary <object, object> enriched = killr.Movies("Young Guns").enrich(InDegree, OutDegree).Next(); pairs = String.Join(", ", enriched.Select(kvp => kvp.Key + "=" + kvp.Value.ToString())); Console.WriteLine($"[{pairs}]"); PrintHeader("Insert/update movie and a actors for that movie", "killr.movie(\"m100000\", \"Manos: The Hands of Fate\",...).actor(...)"); killr.Movie("m100000", "Manos: The Hands of Fate", 1966, 70, "USA", "Sun City Films"). Ensure <Vertex, object, Vertex>(__KillrVideo.Actor("p1000000", "Tom Neyman")). Ensure <Vertex, object, Vertex>(__KillrVideo.Actor("p1000001", "John Reynolds")). Ensure <Vertex, object, Vertex>(__KillrVideo.Actor("p1000002", "Diane Mahree")). Iterate(); Console.WriteLine("Updated 'Manos: The Hands of Fate'"); PrintHeader("Get the actors for the newly added movie", "killr.movies(\"Manos: The Hands of Fate\").actors().values(\"name\")"); results = killr.Movies("Manos: The Hands of Fate").Actors().Values <String>("name").ToList(); PrintItems(results); }
public void Test_Infrastructure() { using (var cluster = DseCluster.Builder().AddContactPoint(CcmHelper.InitialContactPoint).Build()) { Assert.DoesNotThrow(() => cluster.Connect()); } }
public Startup(IConfiguration configuration) { Configuration = configuration; String create_keyspace = @"CREATE KEYSPACE IF NOT EXISTS driver_test WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'DC1' : 1 } ; "; String create_user_table = @"CREATE TABLE IF NOT EXISTS driver_test.user ( id uuid, first_name text, last_name text, PRIMARY KEY (id) );"; IDseCluster cluster = DseCluster.Builder() .AddContactPoint("127.0.0.1") .Build(); IDseSession session = cluster.Connect(); session.Execute(create_keyspace); session.Execute(create_user_table); session.Dispose(); }
public void Should_Have_The_Different_ReadTimeout_Per_Statement() { var timeout = 2000; using (var cluster = DseCluster.Builder() .AddContactPoint(CcmHelper.InitialContactPoint) .WithGraphOptions(new GraphOptions().SetName(GraphName).SetReadTimeoutMillis(timeout)) .Build()) { var session = cluster.Connect(); var stopwatch = new Stopwatch(); var stmtTimeout = 500; try { stopwatch.Start(); session.ExecuteGraph(new SimpleGraphStatement("java.util.concurrent.TimeUnit.MILLISECONDS.sleep(1000L);") .SetReadTimeoutMillis(stmtTimeout)); } catch { stopwatch.Stop(); Assert.GreaterOrEqual(stopwatch.ElapsedMilliseconds, stmtTimeout); Assert.Less(stopwatch.ElapsedMilliseconds, timeout); } } }
public void TestFixtureSetup() { if (Values == null || Values.Length == 0) { throw new InconclusiveException("You must specify the values to test"); } CcmHelper.Start(1); Cluster = DseCluster.Builder().AddContactPoint(CcmHelper.InitialContactPoint).Build(); Trace.TraceInformation("Waiting additional time for test Cluster to be ready"); Thread.Sleep(15000); Session = Cluster.Connect(); Session.Execute(string.Format(CreateKeyspaceQuery, Keyspace)); Session.Execute(string.Format("USE {0}", Keyspace)); _queries = new[] { string.Format("CREATE TABLE geotable1 (id text, value '{0}', PRIMARY KEY (id))", TypeName), string.Format("CREATE TABLE keyed (id '{0}', value text, PRIMARY KEY (id))", TypeName), string.Format("INSERT INTO keyed (id, value) VALUES ('{0}', 'hello')", Values[0]), string.Format("CREATE TYPE geo_udt (f text, v '{0}')", TypeName), "CREATE TABLE tbl_udts (id uuid PRIMARY KEY, value frozen<geo_udt>)", string.Format("CREATE TABLE tbl_tuple (id uuid PRIMARY KEY, value tuple<int, '{0}'>)", TypeName), string.Format("CREATE TABLE tbl_list (id uuid PRIMARY KEY, value list<'{0}'>)", TypeName), string.Format("CREATE TABLE tbl_set (id uuid PRIMARY KEY, value set<'{0}'>)", TypeName), string.Format("CREATE TABLE tbl_map (id uuid PRIMARY KEY, value map<text, '{0}'>)", TypeName) }; foreach (var query in _queries) { Session.Execute(query); } }
public void Should_Support_List_As_Parameter() { var names = new[] { "Mario", "Luigi", "Toad", "Bowser", "Peach", "Wario", "Waluigi" }; using (var cluster = DseCluster.Builder() .AddContactPoint(CcmHelper.InitialContactPoint) .WithGraphOptions(new GraphOptions().SetName(GraphName)) .Build()) { var session = cluster.Connect(); var schemaCharacterQuery = "" + "schema.propertyKey(\"characterName\").Text().create();\n" + "schema.vertexLabel(\"character\").properties(\"characterName\").create();"; session.ExecuteGraph(new SimpleGraphStatement(schemaCharacterQuery)); var createChars = session.ExecuteGraph(new SimpleGraphStatement("characters.each { character -> " + " graph.addVertex(label, 'character', 'characterName', character);" + "};", new { characters = names })); Assert.AreEqual(names.Length, createChars.ToArray().Length); var rs = session.ExecuteGraph(new SimpleGraphStatement("g.V().hasLabel('character').values('characterName')")); var resultArray = rs.ToArray(); Assert.AreEqual(names.Length, resultArray.Length); foreach (var name in resultArray) { Assert.True(names.Contains(name.ToString())); } } }
public void Should_Have_Infinite_ReadTimeout_Per_Statement() { //setting a really small global timeout to make sure that the query exceeds this time var timeout = 2000; var stmtSleep = 10000L; using (var cluster = DseCluster.Builder() .AddContactPoint(CcmHelper.InitialContactPoint) .WithGraphOptions(new GraphOptions().SetName(GraphName).SetReadTimeoutMillis(timeout)) .Build()) { var session = cluster.Connect(); var stopwatch = new Stopwatch(); try { stopwatch.Start(); session.ExecuteGraph(new SimpleGraphStatement("java.util.concurrent.TimeUnit.MILLISECONDS.sleep(" + stmtSleep + ");") .SetReadTimeoutMillis(Timeout.Infinite)); } finally { stopwatch.Stop(); Assert.GreaterOrEqual(stopwatch.ElapsedMilliseconds, timeout); Assert.GreaterOrEqual(stopwatch.ElapsedMilliseconds, stmtSleep); } } }
public void Should_Support_Types(string type, object value, string expectedString) { using (var cluster = DseCluster.Builder() .AddContactPoint(CcmHelper.InitialContactPoint) .WithGraphOptions(new GraphOptions().SetName(GraphName)) .Build()) { var session = cluster.Connect(); var id = _idGenerator++; var vertexLabel = "vertex" + id; var propertyName = "prop" + id; var schemaQuery = string.Format("schema.propertyKey(propertyName).{0}().ifNotExists().create();\n", type) + "schema.vertexLabel(vertexLabel).properties(propertyName).ifNotExists().create();"; session.ExecuteGraph(new SimpleGraphStatement(schemaQuery, new { vertexLabel = vertexLabel, propertyName = propertyName })); var parameters = new { vertexLabel = vertexLabel, propertyName = propertyName, val = value }; var rs = session.ExecuteGraph(new SimpleGraphStatement("g.addV(label, vertexLabel, propertyName, val)", parameters)); ValidateVertexResult(rs, vertexLabel, propertyName, expectedString); rs = session.ExecuteGraph( new SimpleGraphStatement("g.V().hasLabel(vertexLabel).has(propertyName, val).next()", parameters)); ValidateVertexResult(rs, vertexLabel, propertyName, expectedString); } }
public void Should_Get_Path_With_Labels() { using (var cluster = DseCluster.Builder() .AddContactPoint(CcmHelper.InitialContactPoint) .WithGraphOptions(new GraphOptions().SetName(GraphName)) .Build()) { var session = cluster.Connect(); var rs = session.ExecuteGraph(new SimpleGraphStatement( "g.V().hasLabel('person').has('name', 'marko').as('a').outE('knows').as('b').inV().as('c', 'd')" + ".outE('created').as('e', 'f', 'g').inV().as('h').path()")); foreach (Path path in rs) { Console.WriteLine("checking"); CollectionAssert.AreEqual( new string[][] { new [] { "a" }, new [] { "b" }, new[] { "c", "d" }, new[] { "e", "f", "g" }, new [] { "h" } }, path.Labels); var person = path.Objects.First().ToVertex(); Assert.AreEqual("person", person.Label); Assert.True(person.Properties.ContainsKey("name")); } } }
/// <summary> /// Creates the classic graph using a specific connection /// </summary> public void CreateClassicGraph(string contactPoint, string name) { using (var cluster = DseCluster.Builder().AddContactPoint(TestClusterManager.InitialContactPoint).Build()) { CreateClassicGraph(cluster.Connect(), name); } }
private Vertex IncludeAndQueryVertex(string vertexLabel, string propertyName, string type, object value, string expectedString, bool verifyToString = true) { Vertex vertex = null; using (var cluster = DseCluster.Builder() .AddContactPoint(TestClusterManager.InitialContactPoint) .WithGraphOptions(new GraphOptions().SetName(GraphName)) .Build()) { var session = cluster.Connect(); var schemaQuery = string.Format("schema.propertyKey(propertyName).{0}.ifNotExists().create();\n", type) + "schema.vertexLabel(vertexLabel).properties(propertyName).ifNotExists().create();"; session.ExecuteGraph(new SimpleGraphStatement(schemaQuery, new { vertexLabel = vertexLabel, propertyName = propertyName })); var parameters = new { vertexLabel = vertexLabel, propertyName = propertyName, val = value }; session.ExecuteGraph(new SimpleGraphStatement("g.addV(label, vertexLabel, propertyName, val)", parameters)); var rs = session.ExecuteGraph( new SimpleGraphStatement("g.V().hasLabel(vertexLabel).has(propertyName, val).next()", parameters)); var first = rs.FirstOrDefault(); Assert.NotNull(first); vertex = first.ToVertex(); if (verifyToString) { ValidateVertexResult(vertex, vertexLabel, propertyName, expectedString); } } return(vertex); }
public void Should_Build_A_Cluster_With_Default_Graph_Options() { //without specifying graph options IDseCluster cluster = DseCluster.Builder().AddContactPoint("192.168.1.159").Build(); Assert.NotNull(cluster.Configuration); Assert.NotNull(cluster.Configuration.CassandraConfiguration); Assert.NotNull(cluster.Configuration.GraphOptions); }
public void Should_Build_A_Cluster_With_DseLoadBalancingPolicy() { //without specifying load balancing policy IDseCluster cluster = DseCluster.Builder().AddContactPoint("192.168.1.159").Build(); Assert.NotNull(cluster.Configuration); Assert.IsInstanceOf <DseLoadBalancingPolicy>( cluster.Configuration.CassandraConfiguration.Policies.LoadBalancingPolicy); }
public SessionManager() { cluster = DseCluster.Builder().AddContactPoint("127.0.0.1").Build(); session = cluster.Connect("test"); var row = session.Execute("select * from system.local").First(); Console.WriteLine("Podłączono do klastra " + row.GetValue <string>("cluster_name")); PrepareStatements(); }
private static DseSession NewInstance(ISession coreSession, GraphOptions graphOptions = null) { //Cassandra Configuration does not have a public constructor //Create a dummy Cluster instance using (var cluster = DseCluster.Builder().AddContactPoint("127.0.0.1") .WithGraphOptions(graphOptions ?? new GraphOptions()).Build()) { return(new DseSession(coreSession, cluster.Configuration)); } }
public void Should_Build_A_Cluster_With_The_Specified_LoadBalancingPolicy() { var lbp = new TestLoadBalancingPolicy(); IDseCluster cluster = DseCluster.Builder() .AddContactPoint("192.168.1.159") .WithLoadBalancingPolicy(lbp) .Build(); Assert.NotNull(cluster.Configuration); Assert.AreSame(lbp, cluster.Configuration.CassandraConfiguration.Policies.LoadBalancingPolicy); }
public void Should_Build_A_Cluster_With_Graph_Options() { var graphOptions = new GraphOptions(); IDseCluster cluster = DseCluster.Builder() .WithGraphOptions(graphOptions) .AddContactPoint("192.168.1.159") .Build(); Assert.NotNull(cluster.Configuration); Assert.NotNull(cluster.Configuration.CassandraConfiguration); Assert.AreSame(graphOptions, cluster.Configuration.GraphOptions); }
public void OneTimeSetUp() { TestClusterManager.CreateNew(1, new TestClusterOptions { Workloads = new[] { "graph" } }); CreateClassicGraph(TestClusterManager.InitialContactPoint, GraphName); _cluster = DseCluster.Builder() .AddContactPoint(TestClusterManager.InitialContactPoint) .WithGraphOptions(new GraphOptions().SetName(GraphName)) .Build(); _session = _cluster.Connect(); }
public static void VerifyCurrentClusterWorkloads(string[] expectedWorkloads) { using (var cluster = DseCluster.Builder() .AddContactPoint(TestClusterManager.InitialContactPoint) .Build()) { cluster.Connect(); foreach (var host in cluster.Metadata.AllHosts()) { CollectionAssert.AreEquivalent(expectedWorkloads, host.Workloads); } } }
public CassandraDBRepository(IOptions <CassandraDBOptions> optionsAccessor, ILoggerFactory loggerFactory) { var options = optionsAccessor.Value; IDseCluster cluster = DseCluster.Builder() .AddContactPoints(options.ContactPoints.Split(',')) .WithAuthProvider(new DsePlainTextAuthProvider(options.Username, options.Password)) .Build(); session = cluster.Connect(); tableName = options.Tablename; logger = loggerFactory.CreateLogger <CassandraDBRepository>(); }
public void Should_Return_Zero_Results() { using (var cluster = DseCluster.Builder() .AddContactPoint(CcmHelper.InitialContactPoint) .WithGraphOptions(new GraphOptions().SetName(GraphName)) .Build()) { var session = cluster.Connect(); var rs = session.ExecuteGraph(new SimpleGraphStatement("g.V().hasLabel('notALabel')")); var resultArray = rs.ToArray(); Assert.AreEqual(0, resultArray.Length); } }
public Guid Post([FromBody] User user) { IDseCluster cluster = DseCluster.Builder() .AddContactPoint("127.0.0.1") .Build(); IDseSession session = cluster.Connect(); Guid user_id = Guid.NewGuid(); var insert_user = session.Prepare( "INSERT INTO driver_test.user (id, first_name, last_name) VALUES(?,?,?)" ); RowSet results = session.Execute(insert_user.Bind(user_id, user.first_name, user.last_name)); return(user_id); }
public void Should_Support_Object_As_Parameter() { var name = "Albert Einstein"; var year = 1879; var field = "Physics"; var citizenship = new[] { "Kingdom of Württemberg", "Switzerland", "Austria", "Germany", "United States" }; using (var cluster = DseCluster.Builder() .AddContactPoint(CcmHelper.InitialContactPoint) .WithGraphOptions(new GraphOptions().SetName(GraphName)) .Build()) { var session = cluster.Connect(); var schemaScientistQuery = "" + "schema.propertyKey(\"year_born\").Int().create()\n" + "schema.propertyKey(\"field\").Text().create()\n" + "schema.propertyKey(\"scientist_name\").Text().create()\n" + "schema.propertyKey(\"country_name\").Text().create()\n" + "schema.vertexLabel(\"scientist\").properties(\"scientist_name\", \"year_born\", \"field\").create()\n" + "schema.vertexLabel(\"country\").properties(\"country_name\").create()\n" + "schema.edgeLabel(\"had_citizenship\").connection(\"scientist\", \"country\").create()"; session.ExecuteGraph(new SimpleGraphStatement(schemaScientistQuery)); session.ExecuteGraph(new SimpleGraphStatement("Vertex scientist = graph.addVertex(label, 'scientist', 'scientist_name', m.name, 'year_born', m.year_born, 'field', m.field);" + " m.citizenship.each { c -> " + " Vertex country = graph.addVertex(label, 'country', 'country_name', c);" + " scientist.addEdge('had_citizenship', country);" + "};", new { m = new { name = name, year_born = year, citizenship = citizenship, field = field } })); var rs = session.ExecuteGraph(new SimpleGraphStatement("g.V().hasLabel('scientist').has('scientist_name', name)", new { name = name })); Vertex einstein = rs.FirstOrDefault(); Assert.NotNull(einstein); Assert.AreEqual("scientist", einstein.Label); Assert.AreEqual(name, einstein.Properties["scientist_name"].ToArray()[0].Get <string>("value")); Assert.AreEqual(year, einstein.Properties["year_born"].ToArray()[0].Get <int>("value")); Assert.AreEqual(field, einstein.Properties["field"].ToArray()[0].Get <string>("value")); var citizenships = session.ExecuteGraph(new SimpleGraphStatement("g.V().hasLabel('scientist').has('scientist_name', name).outE('had_citizenship').inV().values('country_name');", new { name = name })); var citizenshipArray = citizenships.ToArray(); Assert.AreEqual(citizenship.Length, citizenshipArray.Length); foreach (var countryName in citizenshipArray) { Assert.True(citizenship.Contains(countryName.ToString())); } } }
static WarmPathFunction() { var contactPoints = Environment.GetEnvironmentVariable("CassandraContactPoints", EnvironmentVariableTarget.Process); var username = Environment.GetEnvironmentVariable("CassandraUsername", EnvironmentVariableTarget.Process); var password = Environment.GetEnvironmentVariable("CassandraPassword", EnvironmentVariableTarget.Process); tableName = Environment.GetEnvironmentVariable("CassandraTableName", EnvironmentVariableTarget.Process); IDseCluster cluster = DseCluster.Builder() .AddContactPoints(contactPoints.Split(',')) .WithAuthProvider(new DsePlainTextAuthProvider(username, password)) .Build(); session = cluster.Connect(); }
public string FindSparkMaster() { Trace.TraceInformation("GraphMultiNodeTests: FindSparkMaster"); using (var cluster = DseCluster.Builder() .AddContactPoint(TestClusterManager.InitialContactPoint) .WithLoadBalancingPolicy(DseLoadBalancingPolicy.CreateDefault()) .Build()) { var session = cluster.Connect(); var sparksRS = session.Execute(new SimpleStatement("call DseClientTool.getAnalyticsGraphServer();")); var result = sparksRS.ToArray(); var sparkLocation = ((SortedDictionary <string, string>)result.First()[0])["location"]; var sparkHost = sparkLocation.Split(':')[0]; return(sparkHost); } }
public void Should_Support_Multiple_Named_Parameters() { using (var cluster = DseCluster.Builder() .AddContactPoint(CcmHelper.InitialContactPoint) .WithGraphOptions(new GraphOptions().SetName(GraphName)) .Build()) { var session = cluster.Connect(); var rs = session.ExecuteGraph(new SimpleGraphStatement("[a,b]", new { a = 10, b = 20 })); Assert.NotNull(rs); var resultArray = rs.ToArray(); Assert.AreEqual(2, resultArray.Length); Assert.AreEqual(10, resultArray[0].ToInt32()); Assert.AreEqual(20, resultArray[1].ToInt32()); } }
public Table <User> GetTable() { IDseCluster cluster = DseCluster.Builder() .AddContactPoint("127.0.0.1") .Build(); IDseSession session = cluster.Connect(); MappingConfiguration.Global.Define( new Map <User>() .TableName("user") .PartitionKey(u => u.Id) .Column(u => u.Id, cm => cm.WithName("id")) .Column(u => u.FirstName, cm => cm.WithName("first_name")) .Column(u => u.LastName, cm => cm.WithName("last_name"))); var users = new Table <User>(session); return(users); }
public void Should_Support_Named_Parameters() { using (var cluster = DseCluster.Builder() .AddContactPoint(CcmHelper.InitialContactPoint) .WithGraphOptions(new GraphOptions().SetName(GraphName)) .Build()) { var session = cluster.Connect(); var rs = session.ExecuteGraph(new SimpleGraphStatement("g.V().has('name', namedParam)", new { namedParam = "marko" })); Assert.NotNull(rs); var resultArray = rs.ToArray(); Assert.AreEqual(1, resultArray.Length); var vertex = resultArray[0].ToVertex(); Assert.NotNull(vertex); Assert.AreEqual("person", vertex.Label); Assert.AreEqual("marko", vertex.Properties["name"].ToArray()[0].Get <string>("value")); } }
public void Should_Retrieve_Graph_Edges() { using (var cluster = DseCluster.Builder() .AddContactPoint(CcmHelper.InitialContactPoint) .WithGraphOptions(new GraphOptions().SetName(GraphName)) .Build()) { var session = cluster.Connect(); var rs = session.ExecuteGraph(new SimpleGraphStatement("g.E().hasLabel('created')")); var resultArray = rs.ToArray(); Assert.AreEqual(4, resultArray.Length); foreach (Edge edge in resultArray) { Assert.NotNull(edge); Assert.AreEqual("created", edge.Label); Assert.True(edge.Properties.ContainsKey("weight")); } Assert.NotNull(rs); } }
public void Should_Retrieve_Graph_Vertices() { using (var cluster = DseCluster.Builder() .AddContactPoint(CcmHelper.InitialContactPoint) .WithGraphOptions(new GraphOptions().SetName(GraphName)) .Build()) { var session = cluster.Connect(); var rs = session.ExecuteGraph(new SimpleGraphStatement("g.V().has('name', 'marko').out('knows')")); var resultArray = rs.ToArray(); Assert.AreEqual(2, resultArray.Length); foreach (Vertex v in resultArray) { Assert.NotNull(v); Assert.AreEqual("person", v.Label); Assert.True(v.Properties.ContainsKey("name")); } Assert.NotNull(rs); } }