def test_copy_data_from(self):
        try:
            tmpdir = tempfile.mkdtemp()

            # create new database
            with testing.cassandra.Cassandra(base_dir=tmpdir) as cassandra:
                conn = pycassa.system_manager.SystemManager(cassandra.server_list()[0])
                conn.create_column_family('test', 'hello')
                conn.close()

                conn = pycassa.pool.ConnectionPool('test', cassandra.server_list())
                cf = pycassa.ColumnFamily(conn, 'hello')
                cf.insert('score', {'scott': '1', 'tiger': '2'})

            # flushing MemTable (commit log) to SSTable
            with testing.cassandra.Cassandra(base_dir=tmpdir) as cassandra:
                pass

            # create another database from first one
            data_dir = os.path.join(tmpdir, 'data')
            with testing.cassandra.Cassandra(copy_data_from=data_dir) as cassandra:
                conn = pycassa.pool.ConnectionPool('test', cassandra.server_list())
                values = pycassa.ColumnFamily(conn, 'hello').get('score')

                self.assertEqual({'scott': '1', 'tiger': '2'}, values)
        finally:
            rmtree(tmpdir)
    def test_with_cassandra(self):
        with testing.cassandra.Cassandra() as cassandra:
            self.assertIsNotNone(cassandra)

            # connect to cassandra
            conn = pycassa.pool.ConnectionPool('test', cassandra.server_list())
            self.assertIsNotNone(conn)
            self.assertTrue(cassandra.is_alive())

        self.assertFalse(cassandra.is_alive())
    def test_basic(self):
        # start cassandra server
        cassandra = testing.cassandra.Cassandra()
        self.assertIsNotNone(cassandra)
        self.assertEqual(cassandra.server_list(),
                         ['127.0.0.1:%d' % cassandra.cassandra_yaml['rpc_port']])

        # connect to cassandra
        conn = pycassa.pool.ConnectionPool('test', cassandra.server_list())
        self.assertIsNotNone(conn)

        # shutting down
        pid = cassandra.server_pid
        self.assertTrue(cassandra.is_alive())

        cassandra.stop()
        sleep(1)

        self.assertFalse(cassandra.is_alive())
        with self.assertRaises(OSError):
            os.kill(pid, 0)  # process is down