Ejemplo n.º 1
0
  def test_Timestamp(self):
      s = random.randint(0, 999999999999)
      ns = random.randint(0, 1000000000)
      mid = random.randint(0, 200000)
      ts = Timestamp(s, ns, mid)
      self.assertEqual(s, ts.seconds)
      self.assertEqual(ns, ts.nanoseconds)
      self.assertEqual(mid, ts.machine_id)

      t = ts.tuple()
      self.assertEqual(3, len(t))
      self.assertEqual(s, t[0])
      self.assertEqual(ns, t[1])
      self.assertEqual(mid, t[2])

      s = random.randint(0, 999999999999)
      ns = random.randint(0, 1000000000)
      ts = Timestamp(s, ns)
      self.assertEqual(s, ts.seconds)
      self.assertEqual(ns, ts.nanoseconds)
      self.assertEqual(0, ts.machine_id)

      ft = ts.time()
      self.assertIsInstance(ft, float)
      eft = s + (ns / 1000.0 / 1000.0 / 1000.0)
      self.assertEqual(eft, ft)
Ejemplo n.º 2
0
    def test_Timestamp(self):
        s = random.randint(0, 999999999999)
        ns = random.randint(0, 1000000000)
        mid = random.randint(0, 200000)
        ts = Timestamp(s, ns, mid)
        self.assertEqual(s, ts.seconds)
        self.assertEqual(ns, ts.nanoseconds)
        self.assertEqual(mid, ts.machine_id)

        self.assertEqual(Timestamp, type(ts))
        self.assertTrue(isinstance(ts, tuple))

        t = ts.tuple()
        self.assertEqual(3, len(t))
        self.assertEqual(s, t[0])
        self.assertEqual(ns, t[1])
        self.assertEqual(mid, t[2])

        ts2 = Timestamp(ts.seconds, ts.nanoseconds, ts.machine_id)
        self.assertEqual(ts, ts2)

        now = time.time()
        ts2 = Timestamp(now, 0)
        self.assertEqual(int(now), ts2.seconds)
        self.assertEqual(0, ts2.nanoseconds)
        self.assertEqual(0, ts2.machine_id)

        s = random.randint(0, 999999999999)
        ns = random.randint(0, 1000000000)
        ts = Timestamp(s, ns)
        self.assertEqual(s, ts.seconds)
        self.assertEqual(ns, ts.nanoseconds)
        self.assertEqual(0, ts.machine_id)

        ft = ts.time()
        self.assertIsInstance(ft, float)
        eft = s + (ns / 1000.0 / 1000.0 / 1000.0)
        self.assertEqual(eft, ft)

        tsft = Timestamp.from_time(23423.02, 93)
        self.assertEqual(23423, tsft.seconds)
        self.assertEqual(20 * 1000.0 * 1000.0, float(tsft.nanoseconds))
        self.assertEqual(93, tsft.machine_id)
Ejemplo n.º 3
0
  def test_Timestamp(self):
      s = random.randint(0, 999999999999)
      ns = random.randint(0, 1000000000)
      mid = random.randint(0, 200000)
      ts = Timestamp(s, ns, mid)
      self.assertEqual(s, ts.seconds)
      self.assertEqual(ns, ts.nanoseconds)
      self.assertEqual(mid, ts.machine_id)

      self.assertEqual(Timestamp, type(ts))
      self.assertTrue(isinstance(ts, tuple))

      t = ts.tuple()
      self.assertEqual(3, len(t))
      self.assertEqual(s, t[0])
      self.assertEqual(ns, t[1])
      self.assertEqual(mid, t[2])

      ts2 = Timestamp(ts.seconds, ts.nanoseconds, ts.machine_id)
      self.assertEqual(ts, ts2)

      now = time.time()
      ts2 = Timestamp(now, 0)
      self.assertEqual(int(now), ts2.seconds)
      self.assertEqual(0, ts2.nanoseconds)
      self.assertEqual(0, ts2.machine_id)

      s = random.randint(0, 999999999999)
      ns = random.randint(0, 1000000000)
      ts = Timestamp(s, ns)
      self.assertEqual(s, ts.seconds)
      self.assertEqual(ns, ts.nanoseconds)
      self.assertEqual(0, ts.machine_id)

      ft = ts.time()
      self.assertIsInstance(ft, float)
      eft = s + (ns / 1000.0 / 1000.0 / 1000.0)
      self.assertEqual(eft, ft)

      tsft = Timestamp.from_time(23423.02, 93)
      self.assertEqual(23423, tsft.seconds)
      self.assertEqual(20*1000.0*1000.0, float(tsft.nanoseconds))
      self.assertEqual(93, tsft.machine_id)
Ejemplo n.º 4
0
    def test_timestamp(self):
        ts_schema = StreamSchema('tuple<int32 a, timestamp ts>').as_tuple(named=True)

        ts1 = Timestamp(133001, 302245576, 56)
        ts2s = Timestamp(23543463, 876265298, 32)
        dt1 = ts2s.datetime()
        ts2 = Timestamp.from_datetime(dt1)

        self.assertEqual(ts2s.seconds, ts2s.seconds);

        topo = Topology()
        s = topo.source([(1,ts1), (2,dt1)])
        s = s.map(lambda x : x, schema=ts_schema)
        as_ts = s.map(lambda x : x.ts.tuple())
        s.print()

        tester = Tester(topo)
        tester.tuple_check(s, ts_check)
        tester.tuple_count(s, 2)
        tester.contents(as_ts, [ts1.tuple(), ts2.tuple()])
        tester.test(self.test_ctxtype, self.test_config)
Ejemplo n.º 5
0
    def test_timestamp(self):
        ts_schema = StreamSchema('tuple<int32 a, timestamp ts>').as_tuple(named=True)

        ts1 = Timestamp(133001, 302245576, 56)
        ts2s = Timestamp(23543463, 876265298, 32)
        dt1 = ts2s.datetime()
        ts2 = Timestamp.from_datetime(dt1)

        self.assertEqual(ts2s.seconds, ts2s.seconds);

        topo = Topology()
        s = topo.source([(1,ts1), (2,dt1)])
        s = s.map(lambda x : x, schema=ts_schema)
        as_ts = s.map(lambda x : x.ts.tuple())
        s.print()

        tester = Tester(topo)
        tester.tuple_check(s, ts_check)
        tester.tuple_count(s, 2)
        tester.contents(as_ts, [ts1.tuple(), ts2.tuple()])
        tester.test(self.test_ctxtype, self.test_config)