当前位置: 首页>>代码示例>>C#>>正文


C# Session.CreateKeyspaceIfNotExists方法代码示例

本文整理汇总了C#中Cassandra.Session.CreateKeyspaceIfNotExists方法的典型用法代码示例。如果您正苦于以下问题:C# Session.CreateKeyspaceIfNotExists方法的具体用法?C# Session.CreateKeyspaceIfNotExists怎么用?C# Session.CreateKeyspaceIfNotExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cassandra.Session的用法示例。


在下文中一共展示了Session.CreateKeyspaceIfNotExists方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: checkKSMetadata

        public void checkKSMetadata()
        {
            CCMCluster = CCMBridge.CCMCluster.Create(2, Cluster.Builder());
            try
            {
                Session = CCMCluster.Session;
                Cluster = CCMCluster.Cluster;
                Session.CreateKeyspaceIfNotExists(Keyspace);
                Session.ChangeKeyspace(Keyspace);

                string keyspacename = "keyspace" + Guid.NewGuid().ToString("N").ToLower();
                bool durableWrites = false;
                string strgyClass = "SimpleStrategy";
                short rplctnFactor = 1;
                Session.Cluster.WaitForSchemaAgreement(
                    Session.Execute(
            string.Format(@"CREATE KEYSPACE {0}
             WITH replication = {{ 'class' : '{1}', 'replication_factor' : {2} }}
             AND durable_writes={3};"
            , keyspacename, strgyClass, rplctnFactor.ToString(), durableWrites.ToString())).QueriedHost
                );
                Session.ChangeKeyspace(keyspacename);

                for (int i = 0; i < 10; i++)
                    checkPureMetadata("table" + Guid.NewGuid().ToString("N"), keyspacename);

                KeyspaceMetadata ksmd = Cluster.Metadata.GetKeyspace(keyspacename);
                Assert.True(ksmd.DurableWrites == durableWrites);
                Assert.True(ksmd.Replication.Where(opt => opt.Key == "replication_factor").First().Value == rplctnFactor);
                Assert.True(ksmd.StrategyClass == strgyClass);

            }
            finally
            {
                CCMCluster.Discard();
            }
        }
开发者ID:joaquincasares,项目名称:csharp-driver,代码行数:37,代码来源:MetadataTests.cs

示例2: SetFixture

 public void SetFixture()
 {
     Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
     CCMBridge.ReusableCCMCluster.Setup(2);
     CCMBridge.ReusableCCMCluster.Build(Cluster.Builder());
     Session = CCMBridge.ReusableCCMCluster.Connect("tester");
     Session.CreateKeyspaceIfNotExists(KeyspaceName);
     Session.ChangeKeyspace(KeyspaceName);
 }
开发者ID:hjarraya,项目名称:csharp-driver,代码行数:9,代码来源:ComplexTests.cs

示例3: checkMetadata

        public void checkMetadata(string TableName = null, string KeyspaceName = null, TableOptions tableOptions = null)
        {
            CCMCluster = CCMBridge.CCMCluster.Create(2, Cluster.Builder());
            try
            {
                Session = CCMCluster.Session;
                Cluster = CCMCluster.Cluster;
                Session.CreateKeyspaceIfNotExists(Keyspace);
                Session.ChangeKeyspace(Keyspace);

                checkPureMetadata(TableName, KeyspaceName, tableOptions);
            }
            finally
            {
                CCMCluster.Discard();
            }
        }
开发者ID:joaquincasares,项目名称:csharp-driver,代码行数:17,代码来源:MetadataTests.cs

示例4: CreateKeyspaceWithPropertiesTest

        public void CreateKeyspaceWithPropertiesTest(string strategy_class)
        {
            CCMCluster = CCMBridge.CCMCluster.Create(2, Cluster.Builder());
            try
            {
                Session = CCMCluster.Session;
                Cluster = CCMCluster.Cluster;

                Randomm rndm = new Randomm(DateTime.Now.Millisecond);
                bool durable_writes = rndm.NextBoolean();

                int? replication_factor = null;
                int? data_centers_count = null;
                Dictionary<string, int> datacenters_replication_factors = null;

                if (strategy_class == ReplicationStrategies.SimpleStrategy)
                {
                    replication_factor = rndm.Next(1, 21);
                    Session.CreateKeyspaceIfNotExists(Keyspace,ReplicationStrategies.CreateSimpleStrategyReplicationProperty((int)replication_factor), durable_writes);
                    Session.ChangeKeyspace(Keyspace);
                }
                else
                    if (strategy_class == ReplicationStrategies.NetworkTopologyStrategy)
                    {
                        data_centers_count = rndm.Next(1, 11);
                        datacenters_replication_factors = new Dictionary<string, int>((int)data_centers_count);
                        for (int i = 0; i < data_centers_count; i++)
                            datacenters_replication_factors.Add("dc" + i.ToString(), rndm.Next(1, 21));
                        Session.CreateKeyspaceIfNotExists(Keyspace, ReplicationStrategies.CreateNetworkTopologyStrategyReplicationProperty(datacenters_replication_factors), durable_writes);
                    }

                KeyspaceMetadata ksmd = Cluster.Metadata.GetKeyspace(Keyspace);
                Assert.Equal(strategy_class, ksmd.StrategyClass);
                Assert.Equal(durable_writes, ksmd.DurableWrites);
                if (replication_factor != null)
                    Assert.Equal(replication_factor, ksmd.Replication["replication_factor"]);
                if (datacenters_replication_factors != null)
                    Assert.True(datacenters_replication_factors.SequenceEqual(ksmd.Replication));
            }
            finally
            {
                CCMCluster.Discard();
            }
        }
开发者ID:joaquincasares,项目名称:csharp-driver,代码行数:44,代码来源:MetadataTests.cs

示例5: Connect

 public static Session Connect(string keyspace = null)
 {
     int tryNo = 0;
     RETRY:
     try
     {
         Session = Cluster.Connect();
         if (keyspace != null)
         {
             Session.CreateKeyspaceIfNotExists(keyspace);
             Session.ChangeKeyspace(keyspace);
         }
         return Session;
     }
     catch (NoHostAvailableException e)
     {
         if (tryNo < 10)
         {
             Console.WriteLine("CannotConnect to CCM node - give another try");
             tryNo++;
             Thread.Sleep(1000);
             goto RETRY;
         }
         foreach (var entry in e.Errors)
             Trace.TraceError("Error connecting to " + entry.Key + ": " + entry.Value);
         throw new InvalidOperationException(null, e);
     }
 }
开发者ID:hjarraya,项目名称:csharp-driver,代码行数:28,代码来源:CCMBridge.cs

示例6: SetFixture

 public void SetFixture()
 {
     Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
     CCMCluster = CCMBridge.CCMCluster.Create(2, Cluster.Builder());
     Session = CCMCluster.Session;
     Cluster = CCMCluster.Cluster;
     Session.CreateKeyspaceIfNotExists(Keyspace);
     Session.ChangeKeyspace(Keyspace);
 }
开发者ID:joaquincasares,项目名称:csharp-driver,代码行数:9,代码来源:Basics.cs


注:本文中的Cassandra.Session.CreateKeyspaceIfNotExists方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。