コード例 #1
0
  private void setup() throws IOException, TTransportException {
    int listenPort = DatabaseDescriptor.getThriftPort();

    Thread.setDefaultUncaughtExceptionHandler(
        new Thread.UncaughtExceptionHandler() {
          public void uncaughtException(Thread t, Throwable e) {
            logger.error("Fatal exception in thread " + t, e);
          }
        });

    CassandraServer peerStorageServer = new CassandraServer();
    peerStorageServer.start();
    Cassandra.Processor processor = new Cassandra.Processor(peerStorageServer);

    // Transport
    TServerSocket tServerSocket =
        new TServerSocket(new InetSocketAddress(FBUtilities.getHostName(), listenPort));

    // Protocol factory
    TProtocolFactory tProtocolFactory = new TBinaryProtocol.Factory();

    // ThreadPool Server
    TThreadPoolServer.Options options = new TThreadPoolServer.Options();
    options.minWorkerThreads = 64;
    serverEngine =
        new TThreadPoolServer(
            new TProcessorFactory(processor),
            tServerSocket,
            new TTransportFactory(),
            new TTransportFactory(),
            tProtocolFactory,
            tProtocolFactory,
            options);
  }
コード例 #2
0
  /** test get_count() to work correctly with 'count' settings around page size. (CASSANDRA-4833) */
  @Test
  public void test_get_count() throws Exception {
    Schema.instance.clear(); // Schema are now written on disk and will be reloaded
    new EmbeddedCassandraService().start();
    ThriftSessionManager.instance.setCurrentSocket(new InetSocketAddress(9160));

    DecoratedKey key = Util.dk("testkey");
    for (int i = 0; i < 3050; i++) {
      RowMutation rm = new RowMutation("Keyspace1", key.key);
      rm.add(
          new QueryPath("Standard1", null, ByteBufferUtil.bytes(String.valueOf(i))),
          ByteBufferUtil.EMPTY_BYTE_BUFFER,
          System.currentTimeMillis());
      rm.apply();
    }

    CassandraServer server = new CassandraServer();
    server.set_keyspace("Keyspace1");

    // same as page size
    int count =
        server.get_count(
            key.key, new ColumnParent("Standard1"), predicateWithCount(1024), ConsistencyLevel.ONE);
    assert count == 1024 : "expected 1024 but was " + count;

    // 1 above page size
    count =
        server.get_count(
            key.key, new ColumnParent("Standard1"), predicateWithCount(1025), ConsistencyLevel.ONE);
    assert count == 1025 : "expected 1025 but was " + count;

    // above number of columns
    count =
        server.get_count(
            key.key, new ColumnParent("Standard1"), predicateWithCount(4000), ConsistencyLevel.ONE);
    assert count == 3050 : "expected 3050 but was " + count;

    // same as number of columns
    count =
        server.get_count(
            key.key, new ColumnParent("Standard1"), predicateWithCount(3050), ConsistencyLevel.ONE);
    assert count == 3050 : "expected 3050 but was " + count;

    // 1 above number of columns
    count =
        server.get_count(
            key.key, new ColumnParent("Standard1"), predicateWithCount(3051), ConsistencyLevel.ONE);
    assert count == 3050 : "expected 3050 but was " + count;
  }