Revision 619b12df test/hs/Test/Ganeti/Locking/Allocation.hs

b/test/hs/Test/Ganeti/Locking/Allocation.hs
39 39

  
40 40
import Ganeti.BasicTypes
41 41
import Ganeti.Locking.Allocation
42
import Ganeti.Locking.Types
42 43

  
43 44
{-
44 45

  
......
52 53
data TestOwner = TestOwner Int deriving (Ord, Eq, Show)
53 54

  
54 55
instance Arbitrary TestOwner where
55
  arbitrary = TestOwner <$> choose (0, 7)
56
  arbitrary = TestOwner <$> choose (0, 2)
56 57

  
57
data TestLock = TestLock Int deriving (Ord, Eq, Show)
58
data TestLock = TestBigLock
59
              | TestCollectionLockA
60
              | TestLockA Int
61
              | TestCollectionLockB
62
              | TestLockB Int
63
              deriving (Ord, Eq, Show)
58 64

  
59 65
instance Arbitrary TestLock where
60
  arbitrary = TestLock <$> choose (0, 7)
61

  
66
  arbitrary =  frequency [ (1, elements [ TestBigLock
67
                                        , TestCollectionLockA
68
                                        , TestCollectionLockB
69
                                        ])
70
                         , (2, TestLockA <$> choose (0, 2))
71
                         , (2, TestLockB <$> choose (0, 2))
72
                         ]
73

  
74
instance Lock TestLock where
75
  lockImplications (TestLockA _) = [TestCollectionLockA, TestBigLock]
76
  lockImplications (TestLockB _) = [TestCollectionLockB, TestBigLock]
77
  lockImplications TestBigLock = []
78
  lockImplications _ = [TestBigLock]
62 79

  
63 80
{-
64 81

  
......
79 96
instance (Arbitrary a, Arbitrary b) => Arbitrary (UpdateRequest a b) where
80 97
  arbitrary = UpdateRequest <$> arbitrary <*> arbitrary
81 98

  
82
-- | Fold a sequence of update requests; all allocationscan be obtained in
99
-- | Fold a sequence of update requests; all allocations can be obtained in
83 100
-- this way, starting from the empty allocation.
84
foldUpdates :: (Ord a, Ord b, Show b)
85
            => LockAllocation b a -> [UpdateRequest a b] -> LockAllocation b a
101
foldUpdates :: (Lock a, Ord b, Show b)
102
            => LockAllocation a b -> [UpdateRequest b a] -> LockAllocation a b
86 103
foldUpdates = foldl (\s (UpdateRequest owner updates) ->
87 104
                      fst $ updateLocks owner updates s)
88 105

  
89
instance (Arbitrary a, Arbitrary b, Ord a, Ord b, Show a, Show b)
106
instance (Arbitrary a, Lock a, Arbitrary b, Ord b, Show b)
90 107
          => Arbitrary (LockAllocation a b) where
91 108
  arbitrary = foldUpdates emptyAllocation <$> arbitrary
92 109

  

Also available in: Unified diff