Changeset 22 for protocol/src
- Timestamp:
- 09/22/20 16:26:36 (4 years ago)
- Location:
- protocol/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
protocol/src/main/java/geniusweb/protocol/session/mopac/MOPAC.java
r21 r22 145 145 ProtocolToPartyConnFactory connectionfactory) { 146 146 try { 147 System.out.println("starting MOPAC");147 //System.out.println("starting MOPAC"); 148 148 // we're in Phase.INIT still 149 149 connect(connectionfactory); … … 314 314 final ProtocolToPartyConn partyconn, final Action action, 315 315 long now) { 316 System.out.println("received " + action);316 //System.out.println("received " + action); 317 317 state = state.with(partyconn.getParty(), action, now); 318 318 checkEndPhase(System.currentTimeMillis()); … … 341 341 342 342 state = state.nextPhase(now); 343 343 344 startPhase(now); 344 345 } … … 351 352 */ 352 353 private void broadcastNegotiators(Inform info) { 353 System.out.println("broadcasting " + info);354 //System.out.println("broadcasting " + info); 354 355 for (PartyId party : state.getPhase().getPartyStates() 355 356 .getNegotiatingParties()) { -
protocol/src/main/java/geniusweb/protocol/session/mopac/MOPACState.java
r21 r22 14 14 import geniusweb.actions.PartyId; 15 15 import geniusweb.inform.Agreements; 16 import geniusweb.inform.OptIn; 16 17 import geniusweb.progress.Progress; 17 18 import geniusweb.progress.ProgressRounds; … … 22 23 import geniusweb.protocol.session.SessionState; 23 24 import geniusweb.protocol.session.mopac.phase.OfferPhase; 25 import geniusweb.protocol.session.mopac.phase.OptInPhase; 24 26 import geniusweb.protocol.session.mopac.phase.Phase; 25 27 import geniusweb.protocol.session.saop.SAOPSettings; … … 127 129 /** 128 130 * @param now current time ms since 1970 129 * @return the max possible duration in ms of th is phase. Maybe negative if130 * ew are past deadline131 * @return the max possible duration in ms of the NEXT phase. Maybe 0 or 132 * negative if past deadline. 131 133 */ 132 134 private Long getAvailablePhaseTime(long now) { 135 // explicit check, to check also the round counts. 136 if (incrementProgress().isPastDeadline(now + Phase.PHASE_MINTIME)) 137 return 0l; 133 138 return Math.min(progress.getTerminationTime().getTime() - now, 134 139 Phase.PHASE_MAXTIME); … … 196 201 Phase newphase = phase.next(now, 197 202 Math.min(remainingNegoTime, Phase.PHASE_MAXTIME)); 198 Progress newprogress = progress; 199 if (newphase instanceof OfferPhase 200 && progress instanceof ProgressRounds) 201 newprogress = ((ProgressRounds) progress).advance(); 202 203 return new MOPACState(newphase, actions, connections, newprogress, 204 getSettings(), partyprofiles); 203 204 return new MOPACState(newphase, actions, connections, 205 incrementProgress(), getSettings(), partyprofiles); 206 } 207 208 /** 209 * 210 * @return the next progress. Progress round advances if phase is 211 * {@link OptIn}. 212 */ 213 private Progress incrementProgress() { 214 if (progress instanceof ProgressRounds && phase instanceof OptInPhase) 215 return ((ProgressRounds) progress).advance(); 216 return progress; 205 217 } 206 218 … … 217 229 */ 218 230 public boolean isNewPhasePossible(long now) { 219 return phase.getPartyStates().getNegotiatingParties().size() >= 2 231 // System.out.println("phase=" + phase); 232 boolean a = phase.getPartyStates().getNegotiatingParties().size() >= 2 220 233 && getAvailablePhaseTime(now) > Phase.PHASE_MINTIME; 234 // System.out.println("newstate possible:" + a); 235 return a; 221 236 } 222 237 -
protocol/src/test/java/geniusweb/protocol/session/amop/AMOPSettingsTest.java
r21 r22 97 97 } 98 98 99 @SuppressWarnings("unused") 99 100 @Test(expected = IllegalArgumentException.class) 100 101 public void constructorNoDeadlineTest() { -
protocol/src/test/java/geniusweb/protocol/session/amop/AMOPStateTest.java
r21 r22 172 172 } 173 173 174 @SuppressWarnings("unused") 174 175 @Test 175 176 public void constructWithNullConnection() { … … 375 376 @Test 376 377 public void testCollectVotes() { 377 Votes vote1AB = new Votes(party1, 378 Arrays.asList(new Vote(party1, a, 2), new Vote(party1, b, 2))); 379 Votes vote2AB = new Votes(party2, 380 Arrays.asList(new Vote(party2, a, 2), new Vote(party2, b, 2))); 381 Votes vote3C = new Votes(party3, Arrays.asList(new Vote(party3, c, 2))); 382 Votes vote4AC = new Votes(party4, 383 Arrays.asList(new Vote(party4, a, 2), new Vote(party4, c, 2))); 378 Votes vote1AB = new Votes(party1, Arrays 379 .asList(new Vote(party1, a, 2, 9), new Vote(party1, b, 2, 9))); 380 Votes vote2AB = new Votes(party2, Arrays 381 .asList(new Vote(party2, a, 2, 9), new Vote(party2, b, 2, 9))); 382 Votes vote3C = new Votes(party3, 383 Arrays.asList(new Vote(party3, c, 2, 9))); 384 Votes vote4AC = new Votes(party4, Arrays 385 .asList(new Vote(party4, a, 2, 9), new Vote(party4, c, 2, 9))); 384 386 // party 1,2,4 vote for A, party 1,2 vote for B, party 3,4 vote for C. 385 387 // the biggest vote is P,Q,S … … 407 409 public void testNextPhase() { 408 410 // copy of above. todo cleanup 409 Votes vote1AB = new Votes(party1, 410 Arrays.asList(new Vote(party1, a, 2), new Vote(party1, b, 2))); 411 Votes vote2AB = new Votes(party2, 412 Arrays.asList(new Vote(party2, a, 2), new Vote(party2, b, 2))); 413 Votes vote3C = new Votes(party3, Arrays.asList(new Vote(party3, c, 2))); 414 Votes vote4AC = new Votes(party4, 415 Arrays.asList(new Vote(party4, a, 2), new Vote(party4, c, 2))); 411 Votes vote1AB = new Votes(party1, Arrays 412 .asList(new Vote(party1, a, 2, 9), new Vote(party1, b, 2, 9))); 413 Votes vote2AB = new Votes(party2, Arrays 414 .asList(new Vote(party2, a, 2, 9), new Vote(party2, b, 2, 9))); 415 Votes vote3C = new Votes(party3, 416 Arrays.asList(new Vote(party3, c, 2, 9))); 417 Votes vote4AC = new Votes(party4, Arrays 418 .asList(new Vote(party4, a, 2, 9), new Vote(party4, c, 2, 9))); 416 419 // party 1,2,4 vote for A, party 1,2 vote for B, party 3,4 vote for C. 417 420 // the biggest vote is P,Q,S -
protocol/src/test/java/geniusweb/protocol/tournament/allpermutations/AllPermutationsSettingsTest.java
r18 r22 68 68 profile2 = new ProfileRef("profile2"); 69 69 profile3 = new ProfileRef("profile3"); 70 ProfileListprofiles1 = new ProfileList(Arrays.asList(profile1));71 ProfileListprofiles2 = new ProfileList(Arrays.asList(profile2));72 ProfileListprofiles3 = new ProfileList(Arrays.asList(profile3));70 profiles1 = new ProfileList(Arrays.asList(profile1)); 71 profiles2 = new ProfileList(Arrays.asList(profile2)); 72 profiles3 = new ProfileList(Arrays.asList(profile3)); 73 73 74 74 List<ProfileList> profiles = Arrays.asList(profiles1, profiles2, … … 137 137 } 138 138 139 @SuppressWarnings("unused") 139 140 @Test(expected = IllegalArgumentException.class) 140 141 public void testNullParties() { … … 145 146 } 146 147 148 @SuppressWarnings("unused") 147 149 @Test(expected = IllegalArgumentException.class) 148 150 public void testNoParties() { … … 153 155 } 154 156 157 @SuppressWarnings("unused") 155 158 @Test(expected = IllegalArgumentException.class) 156 159 public void testNullProfiles() { … … 159 162 } 160 163 164 @SuppressWarnings("unused") 161 165 @Test(expected = IllegalArgumentException.class) 162 166 public void testInsufficientProfiles() { … … 167 171 } 168 172 173 @SuppressWarnings("unused") 169 174 @Test(expected = IllegalArgumentException.class) 170 175 public void testNullSessionSettings() { … … 175 180 } 176 181 182 @SuppressWarnings("unused") 177 183 @Test(expected = IllegalArgumentException.class) 178 184 public void testOnePartyPerSession() { … … 189 195 } 190 196 191 // @Test192 // public void makeCobTest() throws URISyntaxException {193 // // Check that the cob party gets profile without the query part194 // String profilebase = "ws://1.2.3.4:8080/profilesserver-a.b.c/websocket/get/someprofile";195 // String partybase = "http://131.180.202.213:8080/partiesserver/run/";196 // String query = "?a=2&partial=4";197 // PartyWithProfile partyprofile = AllPermutationsSettings.makeCob(198 // new PartyRef(partybase + AllPermutationsSettings.COB_PARTY),199 // new ProfileRef(profilebase + query));200 // assertEquals(profilebase,201 // partyprofile.getProfile().getURI().toString());202 // assertEquals(partybase + AllPermutationsSettings.COB_PARTY,203 // partyprofile.getParty().getPartyRef().getURI().toString());204 // }205 206 197 }
Note:
See TracChangeset
for help on using the changeset viewer.