Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

############################################################################### 

# (c) Copyright 2016 CERN # 

# # 

# This software is distributed under the terms of the GNU General Public # 

# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # 

# # 

# In applying this licence, CERN does not waive the privileges and immunities # 

# granted to it by virtue of its status as an Intergovernmental Organization # 

# or submit itself to any jurisdiction. # 

############################################################################### 

''' 

@author: Stefan-Gabriel CHITIC 

''' 

 

import unittest 

 

from lbCVMFSTools.TaskHandlerInterface import TaskHandlerInterface 

from lbCVMFSTools.Scheduler import Scheduler 

from lbCVMFSTools.Injector import injector 

from lbCVMFSTools.TransactionHandlerInterface import \ 

TransactionHandlerInterface 

 

 

class WorkspaceImpl(TaskHandlerInterface): 

 

def __init__(self): 

self.perform_task_ok = False 

self.perform_task_ko = False 

 

def get_list_of_tasks(self): 

return ['task1', 'task2', 'task3'] 

 

def perform_task(self, task): 

if task == 'task3': 

self.perform_task_ko = True 

raise Exception("Exception test") 

self.perform_task_ok = True 

 

def preTransaction(self): 

pass 

 

def postTransaction(self): 

pass 

 

 

class TransactionImpl(TransactionHandlerInterface): 

 

def __init__(self, *args, **kwargs): 

self.perform_task_rollback = False 

 

def transactionPublish(self): 

pass 

 

def transactionStart(self): 

pass 

 

def transactionAbort(self): 

self.perform_task_rollback = True 

 

 

class TestScheduler(unittest.TestCase): 

 

def setUp(self): 

pass 

 

def tearDown(self): 

pass 

 

def test_schedulerAutoRun(self): 

injector.provide(TaskHandlerInterface, WorkspaceImpl) 

injector.provide(TransactionHandlerInterface, TransactionImpl) 

 

s = Scheduler() 

impls = s.taskHandler 

implTrans = s.transactionHandler 

# check if at least one task was performed ok 

self.assertTrue(impls.perform_task_ok) 

# check if at least one task was performed ko 

self.assertTrue(impls.perform_task_ko) 

# check if at a rollback was performed 

self.assertTrue(implTrans.perform_task_rollback) 

 

def test_schedulerNoAutoRun(self): 

w = WorkspaceImpl() 

setattr(w, 'no_auto_start', True) 

injector.provide_instance(TaskHandlerInterface, w) 

 

s = Scheduler() 

impls = s.taskHandler 

implTrans = s.transactionHandler 

# the schedulers shoun't have run 

self.assertFalse(impls.perform_task_ok) 

s.start() 

# check if at least one task was performed ok 

self.assertTrue(impls.perform_task_ok) 

# check if at least one task was performed ko 

self.assertTrue(impls.perform_task_ko) 

# check if at a rollback was performed 

self.assertTrue(implTrans.perform_task_rollback) 

 

if __name__ == "__main__": 

 

unittest.main()