此测试用例将在第一次通过,但接下来将失败。我不知道为什么它在第二次执行insert方法后没有将列值更新为“value1”。
[TestMethod]
public void TestMethod()
{
client.set_keyspace(KEYSPACE);
byte[] key = utf8Encoding.GetBytes("123456789");
ColumnParent parent = new ColumnParent();
parent.Column_family = "Users";
Column column = new Column();
column.Name = utf8Encoding.GetBytes("columnname1");
column.Timestamp = DateTime.Now.Millisecond;
column.Value = utf8Encoding.GetBytes("value1");
// insert
client.insert(key, parent, column, ConsistencyLevel.ONE);
ColumnPath path = new ColumnPath();
path.Column_family = "Users";
path.Column = utf8Encoding.GetBytes("columnname1");
// search
ColumnOrSuperColumn returnedColumn = client.get(key, path, ConsistencyLevel.ONE);
Assert.AreEqual("value1", utf8Encoding.GetString(returnedColumn.Column.Value));
// update
column.Timestamp = DateTime.Now.Millisecond;
column.Value = utf8Encoding.GetBytes("value2");
client.insert(key, parent, column, ConsistencyLevel.ONE);
returnedColumn = client.get(key, path, ConsistencyLevel.ONE);
Assert.AreEqual("value2", utf8Encoding.GetString(returnedColumn.Column.Value));
答案 0 :(得分:-1)
如果您在代码中连续两次调用,则需要确保时间戳正在递增。使用微秒分辨率并创建一个记住上次返回时间的函数,如果下一次将小于或等于上次返回的时间,则添加一个。
仅使用毫秒分辨率,所有时间戳可能都相同,因此Cassandra会恢复比较字节,因此value2获胜。