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


Java Util类代码示例

本文整理汇总了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();
    }
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:26,代码来源:QueryPagerTest.java

示例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()));
}
 
开发者ID:pgaref,项目名称:ACaZoo,代码行数:18,代码来源:ReadMessageTest.java

示例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());
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:24,代码来源:CleanupTest.java

示例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()));
        }
    }
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:19,代码来源:NameSortTest.java

示例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);
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:24,代码来源:ReadMessageTest.java

示例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();
    }
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:25,代码来源:KeyspaceTest.java

示例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);
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:19,代码来源:RangeTombstoneTest.java

示例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();
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:20,代码来源:AntiCompactionTest.java

示例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);
    }
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:22,代码来源:OutOfSpaceTest.java

示例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();
    }
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:26,代码来源:CommitLogStressTest.java

示例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;

}
 
开发者ID:pgaref,项目名称:ACaZoo,代码行数:20,代码来源:SSTableExportTest.java

示例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()));
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:18,代码来源:PerRowSecondaryIndexTest.java

示例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);
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:24,代码来源:RepairedDataTombstonesTest.java

示例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()));
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:19,代码来源:ReadMessageTest.java

示例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);
    }
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:18,代码来源:OutOfSpaceTest.java


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