Ejemplo n.º 1
0
 def get(self):
     """
     Increments some Counters to play with the feature.
     """
     # Fill datastore with data to show case in admin view
     otherSliceId = (datetime.datetime.utcnow() - datetime.timedelta(days=1)).strftime("%Y-%m-%d")
     for client in ['iOS', 'Android', 'Windows']:
         Counter.increment('newInstalls_' + client, random.randint(1, 5))
         Counter.increment('newInstalls_' + client, random.randint(1, 5), sliceId=otherSliceId)
         
     self.response.write("""
     Counters updated!
     Query for counters <a href="/admin/counters/?prefix=newInstalls">here</a>.
     """)
Ejemplo n.º 2
0
 def testMaxNameLength(self):
     longCounterName = 't' * Counter.NAME_MAX_LENGTH
     
     incrementSuccess = Counter.increment(longCounterName, 1).get_result()
     self.assertTrue(incrementSuccess)
     
     counter = Counter.getCurrent(longCounterName).get_result()
     self.assertEqual(counter.name, longCounterName, "Name integrity was not maintained")
Ejemplo n.º 3
0
 def testSlices(self):
     """ Test using default and custom slices while counting """
     # Default slice
     today = datetime.datetime.utcnow().strftime("%Y-%m-%d")
     Counter.increment('testDefault', 1).get_result()
     counter = Counter.getCurrent('testDefault').get_result()
     self.assertEqual(counter.value, 1)
     self.assertDictEqual(counter.bySlice, {today: 1})
     
     # Custom slice
     futs = [Counter.increment('testCustom', 1, sliceId="13")]
     futs.append(Counter.increment('testCustom', 2, sliceId="12"))
     [fut.get_result() for fut in futs]
     
     counter = Counter.getCurrent('testCustom').get_result()
     self.assertEqual(counter.value, 3)
     self.assertDictEqual(counter.bySlice, {"12": 2, "13": 1})
Ejemplo n.º 4
0
 def testShards(self):
     """ Test that 'getCurrent' correctly retrieves values from different shards """
     futs = []
     for _ in xrange(10):
         # Because of NDB issue I can't perform all at the same time
         # https://code.google.com/p/googleappengine/issues/detail?id=10617
         futs.append(Counter.increment('testShards', nbShards=3).get_result())
     successes = futs  # getAllResults(futs)
     self.assertEqual(10, sum(successes))
     
     counter = Counter.getCurrent('testShards', nbShards=3).get_result()
     self.assertEqual(counter.value, 10)