本文整理汇总了Java中org.apache.cassandra.Util类的典型用法代码示例。如果您正苦于以下问题:Java Util类的具体用法?Java Util怎么用?Java Util使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Util类属于org.apache.cassandra包,在下文中一共展示了Util类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addData
import org.apache.cassandra.Util; //导入依赖的package包/类
@BeforeClass
public static void addData()
{
cfs().clearUnsafe();
int nbKeys = 10;
int nbCols = 10;
/*
* Creates the following data:
* k1: c1 ... cn
* ...
* ki: c1 ... cn
*/
for (int i = 0; i < nbKeys; i++)
{
Mutation rm = new Mutation(KS, bytes("k" + i));
ColumnFamily cf = rm.addOrGet(CF);
for (int j = 0; j < nbCols; j++)
cf.addColumn(Util.column("c" + j, "", 0));
rm.applyUnsafe();
}
}
示例2: testGetColumn
import org.apache.cassandra.Util; //导入依赖的package包/类
@Test
public void testGetColumn() throws IOException, ColumnFamilyNotDefinedException
{
Keyspace keyspace = Keyspace.open("Keyspace1");
RowMutation rm;
DecoratedKey dk = Util.dk("key1");
// add data
rm = new RowMutation("Keyspace1", dk.key);
rm.add("Standard1", ByteBufferUtil.bytes("Column1"), ByteBufferUtil.bytes("abcd"), 0);
rm.apply();
ReadCommand command = new SliceByNamesReadCommand("Keyspace1", dk.key, "Standard1", System.currentTimeMillis(), new NamesQueryFilter(ByteBufferUtil.bytes("Column1")));
Row row = command.getRow(keyspace);
Column col = row.cf.getColumn(ByteBufferUtil.bytes("Column1"));
assertEquals(col.value(), ByteBuffer.wrap("abcd".getBytes()));
}
示例3: testCleanupWithNewToken
import org.apache.cassandra.Util; //导入依赖的package包/类
@Test
public void testCleanupWithNewToken() throws ExecutionException, InterruptedException, UnknownHostException
{
StorageService.instance.getTokenMetadata().clearUnsafe();
Keyspace keyspace = Keyspace.open(KEYSPACE1);
ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CF_STANDARD1);
// insert data and verify we get it back w/ range query
fillCF(cfs, "val", LOOPS);
assertEquals(LOOPS, Util.getAll(Util.cmd(cfs).build()).size());
TokenMetadata tmd = StorageService.instance.getTokenMetadata();
byte[] tk1 = new byte[1], tk2 = new byte[1];
tk1[0] = 2;
tk2[0] = 1;
tmd.updateNormalToken(new BytesToken(tk1), InetAddress.getByName("127.0.0.1"));
tmd.updateNormalToken(new BytesToken(tk2), InetAddress.getByName("127.0.0.2"));
CompactionManager.instance.performCleanup(cfs, 2);
assertEquals(0, Util.getAll(Util.cmd(cfs).build()).size());
}
示例4: validateNameSort
import org.apache.cassandra.Util; //导入依赖的package包/类
private void validateNameSort(Keyspace keyspace, int N) throws IOException
{
for (int i = 0; i < N; ++i)
{
DecoratedKey key = Util.dk(Integer.toString(i));
ColumnFamily cf;
cf = Util.getColumnFamily(keyspace, key, "Standard1");
Collection<Cell> cells = cf.getSortedColumns();
for (Cell cell : cells)
{
String name = ByteBufferUtil.string(cell.name().toByteBuffer());
int j = Integer.valueOf(name.substring(name.length() - 1));
byte[] bytes = j % 2 == 0 ? "a".getBytes() : "b".getBytes();
assertEquals(new String(bytes), ByteBufferUtil.string(cell.value()));
}
}
}
示例5: testGetColumn
import org.apache.cassandra.Util; //导入依赖的package包/类
@Test
public void testGetColumn()
{
ColumnFamilyStore cfs = Keyspace.open(KEYSPACE1).getColumnFamilyStore(CF);
new RowUpdateBuilder(cfs.metadata, 0, ByteBufferUtil.bytes("key1"))
.clustering("Column1")
.add("val", ByteBufferUtil.bytes("abcd"))
.build()
.apply();
ColumnDefinition col = cfs.metadata.getColumnDefinition(ByteBufferUtil.bytes("val"));
int found = 0;
for (FilteredPartition partition : Util.getAll(Util.cmd(cfs).build()))
{
for (Row r : partition)
{
if (r.getCell(col).value().equals(ByteBufferUtil.bytes("abcd")))
++found;
}
}
assertEquals(1, found);
}
示例6: testGetRowNoColumns
import org.apache.cassandra.Util; //导入依赖的package包/类
@Test
public void testGetRowNoColumns() throws Throwable
{
String tableName = createTable("CREATE TABLE %s (a text, b int, c int, PRIMARY KEY (a, b))");
execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?)", "0", 0, 0);
final ColumnFamilyStore cfs = Keyspace.open(KEYSPACE).getColumnFamilyStore(tableName);
for (int round = 0; round < 2; round++)
{
// slice with limit 0
Util.assertEmpty(Util.cmd(cfs, "0").columns("c").withLimit(0).build());
// slice with nothing in between the bounds
Util.assertEmpty(Util.cmd(cfs, "0").columns("c").fromIncl(1).toIncl(1).build());
// fetch a non-existent name
Util.assertEmpty(Util.cmd(cfs, "0").columns("c").includeRow(1).build());
if (round == 0)
cfs.forceBlockingFlush();
}
}
示例7: testTrackTimesPartitionTombstone
import org.apache.cassandra.Util; //导入依赖的package包/类
@Test
public void testTrackTimesPartitionTombstone() throws ExecutionException, InterruptedException
{
Keyspace ks = Keyspace.open(KSNAME);
ColumnFamilyStore cfs = ks.getColumnFamilyStore(CFNAME);
cfs.truncateBlocking();
String key = "rt_times";
int nowInSec = FBUtilities.nowInSeconds();
new Mutation(PartitionUpdate.fullPartitionDelete(cfs.metadata, Util.dk(key), 1000, nowInSec)).apply();
cfs.forceBlockingFlush();
SSTableReader sstable = cfs.getLiveSSTables().iterator().next();
assertTimes(sstable.getSSTableMetadata(), 1000, 1000, nowInSec);
cfs.forceMajorCompaction();
sstable = cfs.getLiveSSTables().iterator().next();
assertTimes(sstable.getSSTableMetadata(), 1000, 1000, nowInSec);
}
示例8: writeFile
import org.apache.cassandra.Util; //导入依赖的package包/类
private SSTableReader writeFile(ColumnFamilyStore cfs, int count)
{
ArrayBackedSortedColumns cf = ArrayBackedSortedColumns.factory.create(cfs.metadata);
for (int i = 0; i < count; i++)
cf.addColumn(Util.column(String.valueOf(i), "a", 1));
File dir = cfs.directories.getDirectoryForNewSSTables();
String filename = cfs.getTempSSTablePath(dir);
SSTableWriter writer = new SSTableWriter(filename,
0,
0,
cfs.metadata,
StorageService.getPartitioner(),
new MetadataCollector(cfs.metadata.comparator));
for (int i = 0; i < count * 5; i++)
writer.append(StorageService.getPartitioner().decorateKey(ByteBufferUtil.bytes(i)), cf);
return writer.closeAndOpenReader();
}
示例9: testFlushUnwriteableDie
import org.apache.cassandra.Util; //导入依赖的package包/类
@Test
public void testFlushUnwriteableDie() throws Throwable
{
makeTable();
KillerForTests killerForTests = new KillerForTests();
JVMStabilityInspector.Killer originalKiller = JVMStabilityInspector.replaceKiller(killerForTests);
DiskFailurePolicy oldPolicy = DatabaseDescriptor.getDiskFailurePolicy();
try (Closeable c = Util.markDirectoriesUnwriteable(getCurrentColumnFamilyStore()))
{
DatabaseDescriptor.setDiskFailurePolicy(DiskFailurePolicy.die);
flushAndExpectError();
Assert.assertTrue(killerForTests.wasKilled());
Assert.assertFalse(killerForTests.wasKilledQuietly()); //only killed quietly on startup failure
}
finally
{
DatabaseDescriptor.setDiskFailurePolicy(oldPolicy);
JVMStabilityInspector.replaceKiller(originalKiller);
}
}
示例10: run
import org.apache.cassandra.Util; //导入依赖的package包/类
public void run()
{
RateLimiter rl = rateLimit != 0 ? RateLimiter.create(rateLimit) : null;
final Random rand = random != null ? random : ThreadLocalRandom.current();
while (!stop)
{
if (rl != null)
rl.acquire();
ByteBuffer key = randomBytes(16, rand);
UpdateBuilder builder = UpdateBuilder.create(Schema.instance.getCFMetaData("Keyspace1", "Standard1"), Util.dk(key));
for (int ii = 0; ii < numCells; ii++)
{
int sz = randomSize ? rand.nextInt(cellSize) : cellSize;
ByteBuffer bytes = randomBytes(sz, rand);
builder.newRow("name" + ii).add("val", bytes);
hash = hash(hash, bytes);
++cells;
dataSize += sz;
}
rp = commitLog.add(new Mutation(builder.build()));
counter.incrementAndGet();
}
}
示例11: getDummyWriter
import org.apache.cassandra.Util; //导入依赖的package包/类
public SSTableWriter getDummyWriter() throws IOException
{
File tempSS = tempSSTableFile("Keyspace1", "Standard1");
ColumnFamily cfamily = TreeMapBackedSortedColumns.factory.create("Keyspace1", "Standard1");
SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2);
// Add rowA
cfamily.addColumn(ByteBufferUtil.bytes("colA"), ByteBufferUtil.bytes("valA"), System.currentTimeMillis());
writer.append(Util.dk("rowA"), cfamily);
cfamily.clear();
cfamily.addColumn(ByteBufferUtil.bytes("colB"), ByteBufferUtil.bytes("valB"), System.currentTimeMillis());
writer.append(Util.dk("rowB"), cfamily);
cfamily.clear();
return writer;
}
示例12: testColumnDelete
import org.apache.cassandra.Util; //导入依赖的package包/类
@Test
public void testColumnDelete()
{
// issue a column delete and test that the configured index instance was notified to update
Mutation rm;
rm = new Mutation("PerRowSecondaryIndex", ByteBufferUtil.bytes("k2"));
rm.delete("Indexed1", Util.cellname("indexed"), 1);
rm.apply();
ColumnFamily indexedRow = PerRowSecondaryIndexTest.TestIndex.LAST_INDEXED_ROW;
assertNotNull(indexedRow);
for (Cell cell : indexedRow.getSortedColumns())
assertFalse(cell.isLive());
assertTrue(Arrays.equals("k2".getBytes(), PerRowSecondaryIndexTest.TestIndex.LAST_INDEXED_KEY.array()));
}
示例13: verify2
import org.apache.cassandra.Util; //导入依赖的package包/类
private void verify2(int key, int expectedRows, int minVal, int maxVal)
{
ReadCommand cmd = Util.cmd(getCurrentColumnFamilyStore(), Util.dk(ByteBufferUtil.bytes(key))).build();
int foundRows = 0;
try (ReadOrderGroup orderGroup = cmd.startOrderGroup(); UnfilteredPartitionIterator iterator = cmd.executeLocally(orderGroup))
{
while (iterator.hasNext())
{
UnfilteredRowIterator rowIter = iterator.next();
while (rowIter.hasNext())
{
AbstractRow row = (AbstractRow) rowIter.next();
for (int i = 0; i < row.clustering().size(); i++)
{
foundRows++;
int val = ByteBufferUtil.toInt(row.clustering().get(i));
assertTrue("val=" + val, val >= minVal && val < maxVal);
}
}
}
}
assertEquals(expectedRows, foundRows);
}
示例14: testGetColumn
import org.apache.cassandra.Util; //导入依赖的package包/类
@Test
public void testGetColumn()
{
Keyspace keyspace = Keyspace.open("Keyspace1");
CellNameType type = keyspace.getColumnFamilyStore("Standard1").getComparator();
Mutation rm;
DecoratedKey dk = Util.dk("key1");
// add data
rm = new Mutation("Keyspace1", dk.getKey());
rm.add("Standard1", Util.cellname("Column1"), ByteBufferUtil.bytes("abcd"), 0);
rm.apply();
ReadCommand command = new SliceByNamesReadCommand("Keyspace1", dk.getKey(), "Standard1", System.currentTimeMillis(), new NamesQueryFilter(FBUtilities.singleton(Util.cellname("Column1"), type)));
Row row = command.getRow(keyspace);
Cell col = row.cf.getColumn(Util.cellname("Column1"));
assertEquals(col.value(), ByteBuffer.wrap("abcd".getBytes()));
}
示例15: testFlushUnwriteableStop
import org.apache.cassandra.Util; //导入依赖的package包/类
@Test
public void testFlushUnwriteableStop() throws Throwable
{
makeTable();
DiskFailurePolicy oldPolicy = DatabaseDescriptor.getDiskFailurePolicy();
try (Closeable c = Util.markDirectoriesUnwriteable(getCurrentColumnFamilyStore()))
{
DatabaseDescriptor.setDiskFailurePolicy(DiskFailurePolicy.stop);
flushAndExpectError();
Assert.assertFalse(Gossiper.instance.isEnabled());
}
finally
{
DatabaseDescriptor.setDiskFailurePolicy(oldPolicy);
}
}