本文整理汇总了C#中ISession.CreateKeyspaceIfNotExists方法的典型用法代码示例。如果您正苦于以下问题:C# ISession.CreateKeyspaceIfNotExists方法的具体用法?C# ISession.CreateKeyspaceIfNotExists怎么用?C# ISession.CreateKeyspaceIfNotExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISession
的用法示例。
在下文中一共展示了ISession.CreateKeyspaceIfNotExists方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestSetup
public virtual void TestSetup()
{
var cluster = Cluster.Builder()
.AddContactPoint("127.0.0.1")
.Build();
_session = cluster.Connect();
// Use a unique keyspace for each test fixture named after the test fixture's class name
_keyspaceName = string.Format(TestKeyspaceFormat, GetType().Name.Replace(".", string.Empty));
// Drop and re-create the keyspace
_session.DeleteKeyspaceIfExists(_keyspaceName);
_session.CreateKeyspaceIfNotExists(_keyspaceName);
_session.ChangeKeyspace(_keyspaceName);
_userStore = new CassandraUserStore(_session);
// Exercise the UserManager class in tests since that's how consumers will use CassandarUserStore
UserManager = new UserManager<CassandraUser, Guid>(_userStore);
}
示例2: CheckKeyspaceMetadata
public void CheckKeyspaceMetadata()
{
var clusterInfo = TestUtils.CcmSetup(2);
try
{
Session = clusterInfo.Session;
Cluster = clusterInfo.Cluster;
Session.CreateKeyspaceIfNotExists(Keyspace);
Session.ChangeKeyspace(Keyspace);
var ksName = "keyspace" + Guid.NewGuid().ToString("N").ToLower();
const string strategyClass = "SimpleStrategy";
const bool durableWrites = false;
const int replicationFactor = 1;
Session.WaitForSchemaAgreement(
Session.Execute(string.Format(@"
CREATE KEYSPACE {0}
WITH replication = {{ 'class' : '{1}', 'replication_factor' : {2} }}
AND durable_writes={3};" , ksName, strategyClass, 1, durableWrites))
);
Session.ChangeKeyspace(ksName);
for (var i = 0; i < 10; i++)
{
CheckPureMetadata("table" + Guid.NewGuid().ToString("N"), ksName);
}
var ksmd = Cluster.Metadata.GetKeyspace(ksName);
Assert.True(ksmd.DurableWrites == durableWrites);
Assert.True(ksmd.Replication.First(opt => opt.Key == "replication_factor").Value == replicationFactor);
Assert.True(ksmd.StrategyClass == strategyClass);
}
finally
{
TestUtils.CcmRemove(clusterInfo);
}
}
示例3: CreateTable
///////////////////////////////////////
// Test Helpers
///////////////////////////////////////
private static void CreateTable(ISession session, string tableName, string cqlType)
{
session.CreateKeyspaceIfNotExists(KeyspaceNameDefault);
session.ChangeKeyspace(KeyspaceNameDefault);
session.Execute(string.Format("CREATE TABLE {0} (k INT, i {1}, PRIMARY KEY(k))", tableName, cqlType));
}
示例4: Connect
public static ISession 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)
{
Trace.TraceInformation("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);
}
}
示例5: SetupDefaultCluster
private void SetupDefaultCluster(int nodeLength = 2)
{
if (ClusterInfo != null)
{
TestUtils.CcmRemove(ClusterInfo);
}
ClusterInfo = TestUtils.CcmSetup(nodeLength);
Session = ClusterInfo.Session;
Cluster = ClusterInfo.Cluster;
Session.CreateKeyspaceIfNotExists(ksname);
Session.ChangeKeyspace(ksname);
}
示例6: CreateKeyspaceWithPropertiesTest
private void CreateKeyspaceWithPropertiesTest(string strategyClass)
{
var clusterInfo = TestUtils.CcmSetup(2);
try
{
Session = clusterInfo.Session;
Cluster = clusterInfo.Cluster;
bool durable_writes = Randomm.Instance.NextBoolean();
int? replication_factor = null;
int? data_centers_count = null;
Dictionary<string, int> datacenters_replication_factors = null;
if (strategyClass == ReplicationStrategies.SimpleStrategy)
{
replication_factor = Randomm.Instance.Next(1, 21);
Session.CreateKeyspaceIfNotExists(Keyspace,
ReplicationStrategies.CreateSimpleStrategyReplicationProperty((int) replication_factor),
durable_writes);
Session.ChangeKeyspace(Keyspace);
}
else if (strategyClass == ReplicationStrategies.NetworkTopologyStrategy)
{
data_centers_count = Randomm.Instance.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, Randomm.Instance.Next(1, 21));
Session.CreateKeyspaceIfNotExists(Keyspace,
ReplicationStrategies.CreateNetworkTopologyStrategyReplicationProperty(
datacenters_replication_factors), durable_writes);
}
KeyspaceMetadata ksmd = Cluster.Metadata.GetKeyspace(Keyspace);
Assert.AreEqual(strategyClass, ksmd.StrategyClass);
Assert.AreEqual(durable_writes, ksmd.DurableWrites);
if (replication_factor != null)
Assert.AreEqual(replication_factor, ksmd.Replication["replication_factor"]);
if (datacenters_replication_factors != null)
Assert.True(datacenters_replication_factors.SequenceEqual(ksmd.Replication));
}
finally
{
TestUtils.CcmRemove(clusterInfo);
}
}
示例7: CheckMetadata
private void CheckMetadata(string tableName = null, string keyspaceName = null, TableOptions tableOptions = null)
{
var clusterInfo = TestUtils.CcmSetup(2);
try
{
Session = clusterInfo.Session;
Cluster = clusterInfo.Cluster;
Session.CreateKeyspaceIfNotExists(Keyspace);
Session.ChangeKeyspace(Keyspace);
CheckPureMetadata(tableName, keyspaceName, tableOptions);
}
finally
{
TestUtils.CcmRemove(clusterInfo);
}
}
示例8: UdtMetadataTest
public void UdtMetadataTest()
{
if (Options.Default.CassandraVersion < new Version(2, 1))
{
Assert.Ignore("Test suitable to be run against Cassandra 2.1 or above");
}
const string cqlType1 = "CREATE TYPE phone (alias text, number text)";
const string cqlType2 = "CREATE TYPE address (street text, \"ZIP\" int, phones set<phone>)";
const string cqlTable = "CREATE TABLE user (id int PRIMARY KEY, addr address, main_phone phone)";
var clusterInfo = TestUtils.CcmSetup(1);
try
{
Session = clusterInfo.Session;
Cluster = clusterInfo.Cluster;
Session.CreateKeyspaceIfNotExists(Keyspace);
Session.ChangeKeyspace(Keyspace);
Session.Execute(cqlType1);
Session.Execute(cqlType2);
Session.Execute(cqlTable);
var table = Cluster.Metadata.GetTable(Keyspace, "user");
Assert.AreEqual(3, table.TableColumns.Length);
var udtColumn = table.TableColumns.First(c => c.Name == "addr");
Assert.AreEqual(ColumnTypeCode.Udt, udtColumn.TypeCode);
Assert.IsInstanceOf<UdtColumnInfo>(udtColumn.TypeInfo);
var udtInfo = (UdtColumnInfo)udtColumn.TypeInfo;
Assert.AreEqual(3, udtInfo.Fields.Count);
Assert.AreEqual(Keyspace + ".address", udtInfo.Name);
var phoneDefinition = Cluster.Metadata.GetUdtDefinition(Keyspace, "phone");
Assert.AreEqual(Keyspace + ".phone", phoneDefinition.Name);
Assert.AreEqual(2, phoneDefinition.Fields.Count);
var addressDefinition = Cluster.Metadata.GetUdtDefinition(Keyspace, "address");
Assert.AreEqual(Keyspace + ".address", addressDefinition.Name);
Assert.AreEqual("street,ZIP,phones", String.Join(",", addressDefinition.Fields.Select(f => f.Name)));
Assert.AreEqual(ColumnTypeCode.Int, addressDefinition.Fields.First(f => f.Name == "ZIP").TypeCode);
var phoneSet = addressDefinition.Fields.First(f => f.Name == "phones");
Assert.AreEqual(ColumnTypeCode.Set, phoneSet.TypeCode);
var phoneSetSubType = (SetColumnInfo)phoneSet.TypeInfo;
Assert.AreEqual(ColumnTypeCode.Udt, phoneSetSubType.KeyTypeCode);
Assert.AreEqual(2, ((UdtColumnInfo)phoneSetSubType.KeyTypeInfo).Fields.Count);
}
finally
{
TestUtils.CcmRemove(clusterInfo);
}
}
示例9: TableMetadataAllTypesTest
public void TableMetadataAllTypesTest()
{
var clusterInfo = TestUtils.CcmSetup(1);
try
{
Session = clusterInfo.Session;
Cluster = clusterInfo.Cluster;
Session.CreateKeyspaceIfNotExists(Keyspace);
Session.ChangeKeyspace(Keyspace);
const string tableName = "sample_metadata_alltypes";
Session.Execute(String.Format(TestUtils.CREATE_TABLE_ALL_TYPES, tableName));
var table = Cluster.Metadata
.GetKeyspace(Keyspace)
.GetTableMetadata(tableName);
Assert.IsNotNull(table);
Assert.AreEqual(1, table.TableColumns.Count(c => c.Name == "id"));
Assert.AreEqual(1, table.TableColumns.Count(c => c.Name == "ascii_sample"));
Assert.AreEqual(1, table.TableColumns.Count(c => c.Name == "text_sample"));
Assert.AreEqual(1, table.TableColumns.Count(c => c.Name == "int_sample"));
Assert.AreEqual(1, table.TableColumns.Count(c => c.Name == "bigint_sample"));
Assert.AreEqual(1, table.TableColumns.Count(c => c.Name == "float_sample"));
Assert.AreEqual(1, table.TableColumns.Count(c => c.Name == "double_sample"));
Assert.AreEqual(1, table.TableColumns.Count(c => c.Name == "decimal_sample"));
Assert.AreEqual(1, table.TableColumns.Count(c => c.Name == "blob_sample"));
Assert.AreEqual(1, table.TableColumns.Count(c => c.Name == "boolean_sample"));
Assert.AreEqual(1, table.TableColumns.Count(c => c.Name == "timestamp_sample"));
Assert.AreEqual(1, table.TableColumns.Count(c => c.Name == "inet_sample"));
Assert.AreEqual(1, table.TableColumns.Count(c => c.Name == "timeuuid_sample"));
Assert.AreEqual(1, table.TableColumns.Count(c => c.Name == "map_sample"));
Assert.AreEqual(1, table.TableColumns.Count(c => c.Name == "list_sample"));
Assert.AreEqual(1, table.TableColumns.Count(c => c.Name == "set_sample"));
}
finally
{
TestUtils.CcmRemove(clusterInfo);
}
}
示例10: CompositePartitionKeyMetadata
public void CompositePartitionKeyMetadata()
{
var clusterInfo = TestUtils.CcmSetup(1);
try
{
Session = clusterInfo.Session;
Cluster = clusterInfo.Cluster;
string cql = @"
CREATE TABLE sample_composite_partition1 (
a text,
b int,
c int,
d int,
PRIMARY KEY ((a, b), c))";
Session.CreateKeyspaceIfNotExists(Keyspace);
Session.ChangeKeyspace(Keyspace);
Session.WaitForSchemaAgreement(Session.Execute(cql));
Session.Execute("INSERT INTO sample_composite_partition1 (a, b, c, d) VALUES ('1', 2, 3, 4)");
var rs = Session.Execute("select * from sample_composite_partition1");
Assert.True(rs.GetRows().Count() == 1);
var table = Cluster.Metadata
.GetKeyspace(Keyspace)
.GetTableMetadata("sample_composite_partition1");
Assert.True(table.TableColumns.Count() == 4);
cql = @"
CREATE TABLE sample_composite_partition2 (
a text,
b text,
c int,
d int,
PRIMARY KEY ((a, b, c)))";
Session.WaitForSchemaAgreement(Session.Execute(cql));
table = Cluster.Metadata
.GetKeyspace(Keyspace)
.GetTableMetadata("sample_composite_partition2");
Assert.True(table.TableColumns.Count() == 4);
cql = @"
CREATE TABLE sample_composite_clusteringkey (
a text,
b text,
c timestamp,
d int,
PRIMARY KEY (a, b, c))";
Session.WaitForSchemaAgreement(Session.Execute(cql));
table = Cluster.Metadata
.GetKeyspace(Keyspace)
.GetTableMetadata("sample_composite_clusteringkey");
Assert.True(table.TableColumns.Count() == 4);
}
finally
{
TestUtils.CcmRemove(clusterInfo);
}
}