Changeset 25 for exampleparties/randomparty
- Timestamp:
- 10/08/20 10:17:25 (4 years ago)
- Location:
- exampleparties/randomparty
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
exampleparties/randomparty/pom.xml
r24 r25 6 6 <groupId>geniusweb.exampleparties</groupId> 7 7 <artifactId>randomparty</artifactId> 8 <version>1.5. 3</version> <!-- must equal ${geniusweb.version} -->8 <version>1.5.4</version> <!-- must equal ${geniusweb.version} --> 9 9 <packaging>jar</packaging> 10 10 … … 17 17 <passwd>${env.ARTIFACTORY_PASS}</passwd> 18 18 <jackson-2-version>2.9.6</jackson-2-version> 19 <geniusweb.version>1.5. 3</geniusweb.version>19 <geniusweb.version>1.5.4</geniusweb.version> 20 20 </properties> 21 21 -
exampleparties/randomparty/src/main/java/geniusweb/exampleparties/randomparty/RandomParty.java
r24 r25 63 63 private Settings settings; 64 64 private Votes lastvotes; 65 private String protocol; 65 66 66 67 public RandomParty() { … … 81 82 this.progress = settings.getProgress(); 82 83 this.settings = settings; 84 this.protocol = settings.getProtocol().getURI().getPath(); 85 83 86 } else if (info instanceof ActionDone) { 84 87 Action otheract = ((ActionDone) info).getAction(); … … 88 91 } else if (info instanceof YourTurn) { 89 92 makeOffer(); 90 nextRound();91 93 } else if (info instanceof Finished) { 92 94 getReporter().log(Level.INFO, "Final ourcome:" + info); … … 94 96 lastvotes = vote((Voting) info); 95 97 getConnection().send(lastvotes); 96 nextRound();97 98 } else if (info instanceof OptIn) { 98 99 // just repeat our last vote. 99 100 getConnection().send(lastvotes); 100 nextRound();101 101 } 102 102 } catch (Exception e) { 103 103 throw new RuntimeException("Failed to handle info", e); 104 104 } 105 } 106 107 private void nextRound() { 108 if (progress instanceof ProgressRounds) { 109 progress = ((ProgressRounds) progress).advance(); 110 } 111 105 updateRound(info); 112 106 } 113 107 … … 125 119 126 120 /** 121 * Update {@link #progress} 122 * 123 * @param info the received info. Used to determine if this is the last info 124 * of the round 125 */ 126 private void updateRound(Inform info) { 127 if (protocol == null) 128 return; 129 switch (protocol) { 130 case "SAOP": 131 case "SHAOP": 132 if (!(info instanceof YourTurn)) 133 return; 134 break; 135 case "MOPAC": 136 if (!(info instanceof OptIn)) 137 return; 138 break; 139 default: 140 return; 141 } 142 // if we get here, round must be increased. 143 if (progress instanceof ProgressRounds) { 144 progress = ((ProgressRounds) progress).advance(); 145 } 146 147 } 148 149 /** 127 150 * send our next offer 128 151 */ 129 152 private void makeOffer() throws IOException { 130 153 Action action; 131 String protocol = settings.getProtocol().getURI().getPath();132 154 if ((protocol.equals("SAOP") || protocol.equals("SHAOP")) 133 155 && isGood(lastReceivedBid)) { -
exampleparties/randomparty/src/test/java/geniusweb/exampleparties/randomparty/RandomPartyTest.java
r24 r25 7 7 import static org.mockito.Matchers.eq; 8 8 import static org.mockito.Mockito.mock; 9 import static org.mockito.Mockito.times; 9 10 import static org.mockito.Mockito.verify; 10 11 import static org.mockito.Mockito.when; … … 42 43 import geniusweb.inform.Finished; 43 44 import geniusweb.inform.Inform; 45 import geniusweb.inform.OptIn; 44 46 import geniusweb.inform.Settings; 45 47 import geniusweb.inform.Voting; … … 68 70 private final TestConnection connection = new TestConnection(); 69 71 private final ProtocolRef protocol = new ProtocolRef(SAOP); 72 private final ProtocolRef mopacProtocol = new ProtocolRef("MOPAC"); 70 73 private final ProgressRounds progress = mock(ProgressRounds.class); 71 private Settings settings ;74 private Settings settings, mopacSettings; 72 75 private LinearAdditive profile; 73 76 private final Parameters parameters = new Parameters(); … … 80 83 new ProfileRef(new URI("file:" + PROFILE)), protocol, progress, 81 84 parameters); 85 mopacSettings = new Settings(PARTY1, 86 new ProfileRef(new URI("file:" + PROFILE)), mopacProtocol, 87 progress, parameters); 82 88 83 89 String serialized = new String(Files.readAllBytes(Paths.get(PROFILE)), … … 174 180 175 181 @Test 176 public void testAgentsUpdates Progress() {182 public void testAgentsUpdatesSAOPProgress() { 177 183 party.connect(connection); 178 184 party.notifyChange(settings); … … 180 186 party.notifyChange(new YourTurn()); 181 187 verify(progress).advance(); 188 } 189 190 @Test 191 public void testAgentsUpdatesMOPACProgress() { 192 party.connect(connection); 193 party.notifyChange(mopacSettings); 194 // in mopac, progress happens only after optin phase 195 party.notifyChange(new YourTurn()); 196 verify(progress, times(0)).advance(); 197 party.notifyChange( 198 new Voting(Collections.emptyList(), Collections.emptyMap())); 199 verify(progress, times(0)).advance(); 200 party.notifyChange(new OptIn(Collections.emptyList())); 201 verify(progress, times(1)).advance(); 182 202 } 183 203 … … 199 219 200 220 @Test 201 public void testVoting() {202 party.connect(connection); 203 party.notifyChange( settings);221 public void testVoting() throws URISyntaxException { 222 party.connect(connection); 223 party.notifyChange(mopacSettings); 204 224 205 225 Bid bid = findGoodBid();
Note:
See TracChangeset
for help on using the changeset viewer.