def test_stop_on_child_process(self):
     cassandra = testing.cassandra.Cassandra()
     if os.fork() == 0:
         cassandra.stop()
         os.kill(cassandra.server_pid, 0)  # process is alive (calling stop() is ignored)
         os.kill(os.getpid(), signal.SIGTERM)  # exit tests FORCELY
     else:
         os.wait()
         sleep(1)
         self.assertTrue(cassandra.is_alive())  # process is alive (calling stop() in child is ignored)
    def test_stop(self):
        # start cassandra server
        cassandra = testing.cassandra.Cassandra()
        self.assertTrue(os.path.exists(cassandra.base_dir))
        self.assertTrue(cassandra.is_alive())

        # call stop()
        cassandra.stop()
        self.assertFalse(os.path.exists(cassandra.base_dir))
        self.assertFalse(cassandra.is_alive())

        # call stop() again
        cassandra.stop()
        self.assertFalse(os.path.exists(cassandra.base_dir))
        self.assertFalse(cassandra.is_alive())

        # delete cassandra object after stop()
        del cassandra
    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