def test_add(self): now = datetime.now(), rep1 = model.SJstatGCReport(collect_at=now, ts=100, ygc=3, ygct=15.0, fgc=2, fgct=5.0, gct=20.0) rep2 = model.SJstatGCReport(collect_at=now, ts=20, ygc=1, ygct=10.0, fgc=1, fgct=3.0, gct=15.0) add = rep1 + rep2 self.assertEqual( model.SJstatGCReport(collect_at=now, ts=120, ygc=4, ygct=25.0, fgc=3, fgct=8.0, gct=35.0), add)
def test_sub(self): now = datetime.now() rep1 = model.SJstatGCReport(collect_at=now, ts=100, ygc=3, ygct=15.0, fgc=2, fgct=5.0, gct=20.0) rep2 = model.SJstatGCReport(collect_at=now, ts=20, ygc=1, ygct=10.0, fgc=1, fgct=3.0, gct=15.0) sub = rep1 - rep2 self.assertEqual( model.SJstatGCReport(collect_at=now, ts=80, ygc=2, ygct=5.0, fgc=1, fgct=2.0, gct=5.0), sub)
def test_parse_jstatgc(self): c = ''' Timestamp S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT 13939.4 0.0 30720.0 0.0 30720.0 342016.0 243712.0 4345856.0 776192.2 66896.0 65355.5 8060.0 7777.3 119 40.678 2 2.100 40.678 ''' ctime = datetime.now() statgc_rep = content_parser.parse_jstatgc('1', ctime, 'serv1', c) self.assertIsNotNone(statgc_rep) del statgc_rep['recv_at'] self.assertEqual( model.SJstatGCReport(aid='1', service_id='serv1', collect_at=ctime, ts=13939.4, s0c=0.0, s1c=30720.0, s0u=0.0, s1u=30720.0, ec=342016.0, eu=243712.0, oc=4345856.0, ou=776192.2, mc=66896.0, mu=65355.5, ccsc=8060.0, ccsu=7777.3, ygc=119, ygct=40.678, fgc=2, fgct=2.1, gct=40.678), statgc_rep)
def test_calc(self): rep = model.SJstatGCReport(collect_at=datetime.now(), ts=100, ygc=3, ygct=15.0, fgc=2, fgct=5.0, gct=20.0) self.assertEqual(5, rep.avg_ygct()) self.assertEqual(2.5, rep.avg_fgct()) self.assertEqual(0.8, rep.throughput())
def test_to_gcstat(self): ctime = datetime.now() rep = model.SJstatGCReport(collect_at=datetime.now(), ts=100, service_id='sid', ygc=3, ygct=15.0, fgc=2, fgct=5.0, gct=20.0) gcstat = rep.to_gcstat('test') self.assertEqual( model.JavaGCStat(category='test', start_at=ctime - timedelta(seconds=100), end_at=ctime, samples=0, ygc=3, ygct=15.0, avg_ygct=5.0, fgc=2, fgct=5.0, avg_fgct=2.5, throughput=0.8), gcstat)