Exemplo n.º 1
0
    def test_state_on_construction(self):
        p = Pool(WidgetFactory())
        self.assertEquals(0, p.size())
        self.assertEquals(0, p.available())

        p.shutdown()
        self.assertEquals(0, p.size())
        self.assertEquals(0, p.available())
Exemplo n.º 2
0
 def test_state_on_construction(self):
     p = Pool(WidgetFactory())
     self.assertEquals(0, p.size())
     self.assertEquals(0, p.available())
     
     p.shutdown()
     self.assertEquals(0, p.size())
     self.assertEquals(0, p.available())
Exemplo n.º 3
0
 def test_grow_does_nothing_when_requested_size_less_than_or_equal_to_current_size(self):
     p = Pool(WidgetFactory())
     for i in range(10):
         p.checkout()
     p.grow(5)
     self.assertEquals(10, p.size())
     self.assertEquals(0, p.available())
     
     p.grow(10)
     self.assertEquals(10, p.size())
     self.assertEquals(0, p.available())
Exemplo n.º 4
0
 def test_grow_expands_resource_pool_when_requested_size_greater_than_current_size(self):
     p = Pool(WidgetFactory())
     p.grow(3)
     self.assertEquals(3, p.size())
     self.assertEquals(3, p.available())
     
     for i in range(5):
         p.checkout()
     p.grow(10)
     self.assertEquals(10, p.size())
     self.assertEquals(10-5, p.available())
Exemplo n.º 5
0
    def test_grow_expands_resource_pool_when_requested_size_greater_than_current_size(
            self):
        p = Pool(WidgetFactory())
        p.grow(3)
        self.assertEquals(3, p.size())
        self.assertEquals(3, p.available())

        for i in range(5):
            p.checkout()
        p.grow(10)
        self.assertEquals(10, p.size())
        self.assertEquals(10 - 5, p.available())
Exemplo n.º 6
0
    def test_grow_does_nothing_when_requested_size_less_than_or_equal_to_current_size(
            self):
        p = Pool(WidgetFactory())
        for i in range(10):
            p.checkout()
        p.grow(5)
        self.assertEquals(10, p.size())
        self.assertEquals(0, p.available())

        p.grow(10)
        self.assertEquals(10, p.size())
        self.assertEquals(0, p.available())
Exemplo n.º 7
0
    def test_checkin_checkout(self):
        p = Pool(WidgetFactory())
        w1 = p.checkout()
        log.debug(w1)

        self.assertEquals(1, p.size())
        self.assertEquals(0, p.available())

        p.checkin(w1)
        self.assertEquals(1, p.size())
        self.assertEquals(1, p.available())

        w2 = p.checkout()
        self.assertEquals(w1, w2)
        self.assertEquals(1, p.size())
        self.assertEquals(0, p.available())
Exemplo n.º 8
0
 def test_checkin_checkout(self):
     p = Pool(WidgetFactory())
     w1 = p.checkout()
     log.debug(w1)
     
     self.assertEquals(1, p.size())
     self.assertEquals(0, p.available())
     
     p.checkin(w1)
     self.assertEquals(1, p.size())
     self.assertEquals(1, p.available())
     
     w2 = p.checkout()
     self.assertEquals(w1, w2)
     self.assertEquals(1, p.size())
     self.assertEquals(0, p.available())
Exemplo n.º 9
0
 def test_shrink_reclaims_unused_resources_with_existing_checkouts(self):
     p = Pool(WidgetFactory())
     w1 = p.checkout()
     w2 = p.checkout()
     w3 = p.checkout()
     p.checkin(w1)
     p.checkin(w2)
     p.shrink()
     self.assertEquals(1, p.size())
     self.assertEquals(0, p.available())
Exemplo n.º 10
0
 def test_shrink_reclaims_unused_resources_with_existing_checkouts(self):
     p = Pool(WidgetFactory())
     w1 = p.checkout()
     w2 = p.checkout()
     w3 = p.checkout()
     p.checkin(w1)
     p.checkin(w2)
     p.shrink()
     self.assertEquals(1, p.size())
     self.assertEquals(0, p.available())
Exemplo n.º 11
0
 def test_grow_shrink_combos(self):
     p = Pool(WidgetFactory())
     p.grow(5)
     p.shrink()
     p.grow(20)
     p.checkout()
     p.shrink()
     p.checkout()
     p.grow(3)
     self.assertEquals(3, p.size())
     self.assertEquals(1, p.available())
Exemplo n.º 12
0
 def test_multiple_consumers(self):
     p = Pool(WidgetFactory())
     numConsumers = 10
     consumers = []    
     for c in xrange(numConsumers):
         consumers.append(self.multiple_consumers_thread(c, p, numConsumers))
     for consumer in consumers:
         consumer.join()
     self.assertTrue(p.available() > 0)
     self.assertTrue(p.size() > 0)
     p.shutdown()
Exemplo n.º 13
0
 def test_grow_shrink_combos(self):
     p = Pool(WidgetFactory())
     p.grow(5)
     p.shrink()
     p.grow(20)
     p.checkout()
     p.shrink()
     p.checkout()
     p.grow(3)
     self.assertEquals(3, p.size())
     self.assertEquals(1, p.available())
Exemplo n.º 14
0
 def test_multiple_consumers(self):
     p = Pool(WidgetFactory())
     numConsumers = 10
     consumers = []
     for c in xrange(numConsumers):
         consumers.append(self.multiple_consumers_thread(
             c, p, numConsumers))
     for consumer in consumers:
         consumer.join()
     self.assertTrue(p.available() > 0)
     self.assertTrue(p.size() > 0)
     p.shutdown()
Exemplo n.º 15
0
 def test_shrink_does_nothing_to_pool_when_available_is_zero(self):
     p = Pool(WidgetFactory())
     p.checkout()
     p.shrink()
     self.assertEquals(1, p.size())
     self.assertEquals(0, p.available())
Exemplo n.º 16
0
 def test_shrink_does_nothing_to_empty_pool(self):
     p = Pool(WidgetFactory())
     p.shrink()
     self.assertEquals(0, p.size())
     self.assertEquals(0, p.available())
Exemplo n.º 17
0
 def test_shrink_does_nothing_to_empty_pool(self):
     p = Pool(WidgetFactory())
     p.shrink()
     self.assertEquals(0, p.size())
     self.assertEquals(0, p.available())
Exemplo n.º 18
0
 def test_shrink_does_nothing_to_pool_when_available_is_zero(self):
     p = Pool(WidgetFactory())
     p.checkout()
     p.shrink()
     self.assertEquals(1, p.size())
     self.assertEquals(0, p.available())