4
我應該使用一個計數器與卡桑德拉hector。我複製/粘貼this test case from test code從赫克託:如何設置Hector/Cassandra的計數器?
Mutator<String> m = createMutator(keyspace, se);
MutationResult mr = m.insertCounter(// exception here.
"k", "Counter1", createCounterColumn("name", 5));
assertTrue("Execution time on single counter insert should be > 0", mr.getExecutionTimeMicro() > 0);
assertTrue("Should have operated on a host", mr.getHostUsed() != null);
CounterQuery<String, String> counter = new ThriftCounterColumnQuery<String,String>(keyspace, se, se);
counter.setColumnFamily("Counter1").setKey("k").setName("name");
assertEquals(new Long(5), counter.execute().get().getValue());
,但我得到這個例外,在insertCounter線,因爲C1的是未配置,他說:
me.prettyprint.hector.api.exceptions.HInvalidRequestException: InvalidRequestException(why:unconfigured columnfamily Counter1)
at me.prettyprint.cassandra.service.ExceptionsTranslatorImpl.translate(ExceptionsTranslatorImpl.java:45) ~[hector-core-1.0-5.jar:na]
at me.prettyprint.cassandra.connection.HConnectionManager.operateWithFailover(HConnectionManager.java:264) ~[hector-core-1.0-5.jar:na]
at me.prettyprint.cassandra.model.ExecutingKeyspace.doExecuteOperation(ExecutingKeyspace.java:97) ~[hector-core-1.0-5.jar:na]
at me.prettyprint.cassandra.model.MutatorImpl.execute(MutatorImpl.java:243) ~[hector-core-1.0-5.jar:na]
at me.prettyprint.cassandra.model.MutatorImpl.insertCounter(MutatorImpl.java:285) ~[hector-core-1.0-5.jar:na]
OK,但測試用例沒有按」 t配置Counter1?我如何配置?
謝謝。
感謝phatfingers,但我想應該讓我所有的東西與代碼,赫克託。是否有可能用hector創建一個列家族? – Istao
我添加了在Hector中執行相同任務的代碼。 – phatfingers
另外,您可以快速瀏覽第三個選擇 - 從您的應用程序運行CQL:https://github.com/jsevellec/cassandra-unit/blob/master/src/test/java/org/cassandraunit/DataLoaderAndCQLExecutionTest .java – phatfingers