def setUp(self): print('setting up {}'.format(self.name)) self.server = PelikanServer(self.name) self.server.ready() self.data_client = DataClient(DEFAULT_SERVER) self.admin_client = AdminClient(DEFAULT_ADMIN) self.stats = self.admin_client.stats()
class GenericTest(unittest.TestCase): def __init__(self, binary_name): """initialize based on what server to run the tests against""" if binary_name not in PelikanServer.SUPPORTED_SERVER: raise ValueError('{} is not a valid server binary'.format( {binary_name})) super(GenericTest, self).__init__() self.name = binary_name def setUp(self): print('setting up {}'.format(self.name)) self.server = PelikanServer(self.name) self.server.ready() self.data_client = DataClient(DEFAULT_SERVER) self.admin_client = AdminClient(DEFAULT_ADMIN) self.stats = self.admin_client.stats() def tearDown(self): print('tearing down {}'.format(self.name)) self.data_client.close() self.admin_client.close() self.server.stop() def load(self, fname): """loading a test sequence from a file""" print('loading tests from {}'.format(fname)) self.seq = load_seq(fname) def assertResponse(self, expected): """receive and verify response (a list) matches expectation""" if len(expected) > 0: rsp = self.data_client.response() self.assertEqual( rsp, expected, "expecting response '{}', received '{}'".format(expected, rsp)) def assertStats(self, delta): """delta, a dict, captures the expected change in a subset of metrics""" stats = self.admin_client.stats() for k in delta: self.assertEqual(int(stats[k]) - int(self.stats[k]), delta[k], "expecting '{}' to change by {}, previously {}, currently {}"\ .format(k, delta[k], self.stats[k], stats[k])) self.stats = stats def runTest(self): for d in self.seq: self.data_client.request(d['req']) self.assertResponse(d['rsp']) self.assertStats(d['stat'])
class GenericTest(unittest.TestCase): def setUp(self): self.server = PelikanServer('pelikan_twemcache') self.server.ready() self.data_client = DataClient(DEFAULT_SERVER) self.admin_client = AdminClient(DEFAULT_ADMIN) self.stats = self.admin_client.stats() def tearDown(self): self.data_client.close() self.admin_client.close() self.server.stop() def load(self, fname): """loading a test sequence from a file""" self.seq = load_seq(fname) def assertResponse(self, expected): """receive and verify response (a list) matches expectation""" if len(expected) > 0: rsp = self.data_client.response() self.assertEqual(len(rsp), len(expected)) self.assertEqual(rsp, expected) def assertStats(self, delta): """delta, a dict, captures the expected change in a subset of metrics""" stats = self.admin_client.stats() for k in delta: self.assertEqual(int(stats[k]) - int(self.stats[k]), delta[k], "expecting '{}' to change by {}, previously {}, currently {}"\ .format(k, delta[k], self.stats[k], stats[k])) self.stats = stats def runTest(self): for d in self.seq: self.data_client.request(d['req']) self.assertResponse(d['rsp']) self.assertStats(d['stat'])
def setUp(self): self.server = PelikanServer('pelikan_twemcache') self.server.ready() self.data_client = DataClient(DEFAULT_SERVER) self.admin_client = AdminClient(DEFAULT_ADMIN) self.stats = self.admin_client.stats()
print 'tor IP:', requests.get('http://httpbin.org/ip', proxies=PROXIES).text def tor_disconnect(): """ kill the tor process """ global tor_ps if tor_ps: tor_ps.kill() tor_ps = None if __name__ == '__main__': # register all peers with the aggregator peers = [] for i in range(3): print 'client', i net = NetClient(sys.argv[1], port=8000, key_size=1024) net.register() peer = DataClient(net, data_path='data/demo-data-%d.csv' % i, label_col='dropout', bin_size=5, p_keep=0.9, p_change=0.1) peers.append(peer) print print 'registration complete!' print # have each peer send data anonymously tor_connect() for p in peers: p.perturb_and_send() tor_disconnect()
from client import DataClient, AxesHelper import matplotlib.pyplot as plt client = DataClient() fig = plt.figure() ax1 = fig.add_subplot(1, 2, 1) helper1 = AxesHelper(ax1, client) helper1.histogram1d('a', 10) helper1.update() ax2 = fig.add_subplot(1, 2, 2) helper2 = AxesHelper(ax2, client, selection_callback=helper1.set_selection) helper2.histogram2d('a', 'b', 10, 15) helper2.update() print(fig.canvas.callbacks.callbacks) plt.show()