|
32 | 32 | import static org.hyperledger.fabric.sdk.ServiceDiscovery.SDEndorserState;
|
33 | 33 | import static org.hyperledger.fabric.sdk.ServiceDiscovery.SDLayout;
|
34 | 34 | import static org.junit.Assert.assertEquals;
|
| 35 | +import static org.junit.Assert.assertFalse; |
35 | 36 | import static org.junit.Assert.assertSame;
|
36 | 37 | import static org.junit.Assert.assertTrue;
|
37 | 38 |
|
@@ -335,6 +336,48 @@ public void twoLayoutTwoTwoEachExtrasCommonRandom() throws Exception {
|
335 | 336 |
|
336 | 337 | }
|
337 | 338 |
|
| 339 | + /** |
| 340 | + * Test to ensure layouts and groups are correctly classified |
| 341 | + * as (un)satisfied and (un)satisfiable during proposal response |
| 342 | + * collection by the methods `endorsedList` and `ignoreListSDEndorser`. |
| 343 | + */ |
| 344 | + @Test |
| 345 | + public void loopGoodAndBadTest() { |
| 346 | + |
| 347 | + // Let's say we have a group with 3 endorsers of which we require 2. |
| 348 | + final int requiredInGroup = 2; |
| 349 | + SDEndorser endorser1 = new MockSDEndorser("org1", "localhost:81", 0); |
| 350 | + SDEndorser endorser2 = new MockSDEndorser("org1", "localhost:82", 0); |
| 351 | + SDEndorser endorser3 = new MockSDEndorser("org1", "localhost:83", 0); |
| 352 | + LinkedList<SDEndorser> endorsers = new LinkedList<>(); |
| 353 | + endorsers.add(endorser1); |
| 354 | + endorsers.add(endorser2); |
| 355 | + endorsers.add(endorser3); |
| 356 | + SDLayout layout = new SDLayout(); |
| 357 | + layout.addGroup("G0", requiredInGroup, endorsers); |
| 358 | + SDLayout.SDGroup group = layout.getSDLGroups().iterator().next(); |
| 359 | + |
| 360 | + // If 'endorser1' endorses successfully call `endorsedList`, |
| 361 | + // the group should not be satisfied as we still require 1 more endorser. |
| 362 | + LinkedList<SDEndorser> loopGood = new LinkedList<>(); |
| 363 | + loopGood.add(endorser1); |
| 364 | + assertFalse(layout.endorsedList(loopGood)); // false i.e. not yet satisfied. |
| 365 | + assertEquals(1, group.getStillRequired()); |
| 366 | + |
| 367 | + // If 'endorser2' fails to endorse call `ignoreListSDEndorser`, |
| 368 | + // the group should still be satisfiable as we still have 1 more endorser to try. |
| 369 | + LinkedList<SDEndorser> loopBad = new LinkedList<>(); |
| 370 | + loopBad.add(endorser2); |
| 371 | + assertTrue(layout.ignoreListSDEndorser(loopBad)); // true i.e. still possible to satisfy. |
| 372 | + assertEquals(1, group.getStillRequired()); |
| 373 | + |
| 374 | + // If 'endorser3' endorses, then the group should be satisfied. |
| 375 | + loopGood = new LinkedList<>(); |
| 376 | + loopGood.add(endorser3); |
| 377 | + assertTrue(layout.endorsedList(loopGood)); // true i.e .satisfied. |
| 378 | + assertEquals(0, group.getStillRequired()); |
| 379 | + } |
| 380 | + |
338 | 381 | private static class MockSDEndorser extends SDEndorser {
|
339 | 382 | private MockSDEndorser(String mspid, String endpoint, long ledgerHeight) {
|
340 | 383 | super();
|
|
0 commit comments