github.com/swiftstack/proxyfs@v0.0.0-20201223034610-5434d919416e/liveness/polling_test.go (about) 1 package liveness 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "testing" 7 ) 8 9 // TestComputeLivenessCheckAssignments tests the named func against the following config: 10 // 11 // PeerA - hosting VolumeGroupAA & VolumeGroupAB 12 // PeerB - hosting VolumeGroupBA, VolumeGroupBB, & VolumeGroupBC 13 // PeerC - hosting VolumeGroupCA, VolumeGroupCB, & VolumeGroupCC 14 // PeerD - not hosting any VolumeGroups 15 // 16 // VolumeGroupAA - hosting VolumeAAA & VolumeAAB 17 // VolumeGroupAB - hosting VolumeABA, VolumeABB, and VolumeABC 18 // 19 // VolumeGroupBA - hosting VolumeBAA 20 // VolumeGroupBB - hosting VolumeBBA & VolumeBBB 21 // VolumeGroupBC - hosting VolumeBCA 22 // 23 // VolumeGroupCA - hosting VolumeCAA, VolumeCAB, & VolumeCAC 24 // VolumeGroupCB - hosting VolumeCBA & VolumeCBB 25 // VolumeGroupCC - hosting no volumes 26 // 27 // We will always use livenessCheckRedundancy == 3 28 // We will always use whoAmI == "PeerA" 29 // We will vary observingPeerNameList == []{"PeerA"} and []{"PeerA", "PeerB", "PeerC", "PeerD"} 30 // 31 func TestComputeLivenessCheckAssignments(t *testing.T) { 32 var ( 33 // Peers (other than whoAmI) 34 peerB *peerStruct 35 peerC *peerStruct 36 peerD *peerStruct 37 // VolumeGroups 38 volumeGroupAA *volumeGroupStruct 39 volumeGroupAB *volumeGroupStruct 40 volumeGroupBA *volumeGroupStruct 41 volumeGroupBB *volumeGroupStruct 42 volumeGroupBC *volumeGroupStruct 43 volumeGroupCA *volumeGroupStruct 44 volumeGroupCB *volumeGroupStruct 45 volumeGroupCC *volumeGroupStruct 46 // Volumes 47 volumeAAA *volumeStruct 48 volumeAAB *volumeStruct 49 volumeABA *volumeStruct 50 volumeABB *volumeStruct 51 volumeABC *volumeStruct 52 volumeBAA *volumeStruct 53 volumeBBA *volumeStruct 54 volumeBBB *volumeStruct 55 volumeBCA *volumeStruct 56 volumeCAA *volumeStruct 57 volumeCAB *volumeStruct 58 volumeCAC *volumeStruct 59 volumeCBA *volumeStruct 60 volumeCBB *volumeStruct 61 // Other locals 62 err error 63 externalLivenessReportForAllPeers *LivenessReportStruct 64 externalLivenessReportForAllPeersAsJSON []byte 65 externalLivenessReportForJustPeerA *LivenessReportStruct 66 externalLivenessReportForJustPeerAAsJSON []byte 67 internalLivenessReportForAllPeers *internalLivenessReportStruct 68 internalLivenessReportForJustPeerA *internalLivenessReportStruct 69 observingPeernameListWithAllPeers []string 70 observingPeernameListWithJustPeerA []string 71 ) 72 73 // Setup baseline globals 74 75 globals.whoAmI = "PeerA" 76 globals.myVolumeGroupMap = make(map[string]*volumeGroupStruct) 77 78 volumeGroupAA = &volumeGroupStruct{ 79 peer: nil, 80 name: "VolumeGroupAA", 81 volumeMap: make(map[string]*volumeStruct), 82 } 83 globals.myVolumeGroupMap[volumeGroupAA.name] = volumeGroupAA 84 85 volumeAAA = &volumeStruct{ 86 volumeGroup: volumeGroupAA, 87 name: "VolumeAAA", 88 } 89 volumeGroupAA.volumeMap[volumeAAA.name] = volumeAAA 90 91 volumeAAB = &volumeStruct{ 92 volumeGroup: volumeGroupAA, 93 name: "VolumeAAB", 94 } 95 volumeGroupAA.volumeMap[volumeAAB.name] = volumeAAB 96 97 volumeGroupAB = &volumeGroupStruct{ 98 peer: nil, 99 name: "VolumeGroupAB", 100 volumeMap: make(map[string]*volumeStruct), 101 } 102 globals.myVolumeGroupMap[volumeGroupAB.name] = volumeGroupAB 103 104 volumeABA = &volumeStruct{ 105 volumeGroup: volumeGroupAB, 106 name: "VolumeABA", 107 } 108 volumeGroupAB.volumeMap[volumeAAA.name] = volumeABA 109 110 volumeABB = &volumeStruct{ 111 volumeGroup: volumeGroupAB, 112 name: "VolumeABB", 113 } 114 volumeGroupAB.volumeMap[volumeAAB.name] = volumeABB 115 116 volumeABC = &volumeStruct{ 117 volumeGroup: volumeGroupAB, 118 name: "VolumeABC", 119 } 120 volumeGroupAB.volumeMap[volumeAAB.name] = volumeABC 121 122 peerB = &peerStruct{ 123 name: "PeerB", 124 volumeGroupMap: make(map[string]*volumeGroupStruct), 125 } 126 127 volumeGroupBA = &volumeGroupStruct{ 128 peer: peerB, 129 name: "VolumeGroupBA", 130 volumeMap: make(map[string]*volumeStruct), 131 } 132 peerB.volumeGroupMap[volumeGroupBA.name] = volumeGroupBA 133 134 volumeBAA = &volumeStruct{ 135 volumeGroup: volumeGroupBA, 136 name: "VolumeBAA", 137 } 138 volumeGroupBA.volumeMap[volumeBAA.name] = volumeBAA 139 140 volumeGroupBB = &volumeGroupStruct{ 141 peer: peerB, 142 name: "VolumeGroupBB", 143 volumeMap: make(map[string]*volumeStruct), 144 } 145 peerB.volumeGroupMap[volumeGroupBB.name] = volumeGroupBB 146 147 volumeBBA = &volumeStruct{ 148 volumeGroup: volumeGroupBA, 149 name: "VolumeBBA", 150 } 151 volumeGroupBB.volumeMap[volumeBBA.name] = volumeBBA 152 153 volumeBBB = &volumeStruct{ 154 volumeGroup: volumeGroupBA, 155 name: "VolumeBBB", 156 } 157 volumeGroupBB.volumeMap[volumeBBB.name] = volumeBBB 158 159 volumeGroupBC = &volumeGroupStruct{ 160 peer: peerB, 161 name: "VolumeGroupBC", 162 volumeMap: make(map[string]*volumeStruct), 163 } 164 peerB.volumeGroupMap[volumeGroupBC.name] = volumeGroupBC 165 166 volumeBCA = &volumeStruct{ 167 volumeGroup: volumeGroupBC, 168 name: "VolumeBCA", 169 } 170 volumeGroupBC.volumeMap[volumeBCA.name] = volumeBCA 171 172 peerC = &peerStruct{ 173 name: "PeerC", 174 volumeGroupMap: make(map[string]*volumeGroupStruct), 175 } 176 177 volumeGroupCA = &volumeGroupStruct{ 178 peer: peerC, 179 name: "VolumeGroupCA", 180 volumeMap: make(map[string]*volumeStruct), 181 } 182 peerC.volumeGroupMap[volumeGroupCA.name] = volumeGroupCA 183 184 volumeCAA = &volumeStruct{ 185 volumeGroup: volumeGroupCA, 186 name: "VolumeCAA", 187 } 188 volumeGroupCA.volumeMap[volumeCAA.name] = volumeCAA 189 190 volumeCAB = &volumeStruct{ 191 volumeGroup: volumeGroupCA, 192 name: "VolumeCAB", 193 } 194 volumeGroupCA.volumeMap[volumeCAB.name] = volumeCAB 195 196 volumeCAC = &volumeStruct{ 197 volumeGroup: volumeGroupCA, 198 name: "VolumeCAC", 199 } 200 volumeGroupCA.volumeMap[volumeCAC.name] = volumeCAC 201 202 volumeGroupCB = &volumeGroupStruct{ 203 peer: peerC, 204 name: "VolumeGroupCB", 205 volumeMap: make(map[string]*volumeStruct), 206 } 207 peerC.volumeGroupMap[volumeGroupCB.name] = volumeGroupCB 208 209 volumeCBA = &volumeStruct{ 210 volumeGroup: volumeGroupCB, 211 name: "VolumeCBA", 212 } 213 volumeGroupCB.volumeMap[volumeCBA.name] = volumeCBA 214 215 volumeCBB = &volumeStruct{ 216 volumeGroup: volumeGroupCB, 217 name: "VolumeCBB", 218 } 219 volumeGroupCB.volumeMap[volumeCBB.name] = volumeCBB 220 221 volumeGroupCC = &volumeGroupStruct{ 222 peer: peerC, 223 name: "VolumeGroupCC", 224 volumeMap: make(map[string]*volumeStruct), 225 } 226 peerC.volumeGroupMap[volumeGroupCC.name] = volumeGroupCC 227 228 peerD = &peerStruct{ 229 name: "PeerB", 230 volumeGroupMap: make(map[string]*volumeGroupStruct), 231 } 232 233 globals.peersByName = make(map[string]*peerStruct) 234 235 globals.peersByName["PeerB"] = peerB 236 globals.peersByName["PeerC"] = peerC 237 globals.peersByName["PeerD"] = peerD 238 239 globals.volumeToCheckList = make([]*volumeStruct, 0) 240 241 globals.volumeToCheckList = append(globals.volumeToCheckList, volumeAAA) 242 globals.volumeToCheckList = append(globals.volumeToCheckList, volumeAAB) 243 244 globals.volumeToCheckList = append(globals.volumeToCheckList, volumeABA) 245 globals.volumeToCheckList = append(globals.volumeToCheckList, volumeABB) 246 globals.volumeToCheckList = append(globals.volumeToCheckList, volumeABC) 247 248 globals.volumeToCheckList = append(globals.volumeToCheckList, volumeBAA) 249 250 globals.volumeToCheckList = append(globals.volumeToCheckList, volumeBBA) 251 globals.volumeToCheckList = append(globals.volumeToCheckList, volumeBBB) 252 253 globals.volumeToCheckList = append(globals.volumeToCheckList, volumeBCA) 254 255 globals.volumeToCheckList = append(globals.volumeToCheckList, volumeCAA) 256 globals.volumeToCheckList = append(globals.volumeToCheckList, volumeCAB) 257 globals.volumeToCheckList = append(globals.volumeToCheckList, volumeCAC) 258 259 globals.volumeToCheckList = append(globals.volumeToCheckList, volumeCBA) 260 globals.volumeToCheckList = append(globals.volumeToCheckList, volumeCBB) 261 262 globals.emptyServingPeerToCheckSet = make(map[string]struct{}) 263 264 globals.emptyServingPeerToCheckSet["PeerD"] = struct{}{} 265 266 globals.livenessCheckRedundancy = 3 267 268 // Validate for observingPeerNameList == []{"PeerA"} 269 270 observingPeernameListWithJustPeerA = []string{"PeerA"} 271 272 internalLivenessReportForJustPeerA = computeLivenessCheckAssignments(observingPeernameListWithJustPeerA) 273 274 externalLivenessReportForJustPeerA = convertInternalToExternalLivenessReport(internalLivenessReportForJustPeerA) 275 276 fmt.Println("externalLivenessReportForJustPeerA:") 277 externalLivenessReportForJustPeerAAsJSON, err = json.MarshalIndent(externalLivenessReportForJustPeerA, "", " ") 278 if nil != err { 279 t.Fatal(err) 280 } 281 fmt.Println(string(externalLivenessReportForJustPeerAAsJSON)) 282 283 // TODO: Actually validate it programmatically 284 285 // Validate for observingPeerNameList == []{"PeerA", "PeerB", "PeerC", "PeerD"} 286 287 observingPeernameListWithAllPeers = []string{"PeerA", "PeerB", "PeerC", "PeerD"} 288 289 internalLivenessReportForAllPeers = computeLivenessCheckAssignments(observingPeernameListWithAllPeers) 290 291 externalLivenessReportForAllPeers = convertInternalToExternalLivenessReport(internalLivenessReportForAllPeers) 292 293 fmt.Println("externalLivenessReportForAllPeers:") 294 externalLivenessReportForAllPeersAsJSON, err = json.MarshalIndent(externalLivenessReportForAllPeers, "", " ") 295 if nil != err { 296 t.Fatal(err) 297 } 298 fmt.Println(string(externalLivenessReportForAllPeersAsJSON)) 299 300 // TODO: Actually validate it programmatically 301 302 // All done 303 }