Changeset 22 for protocol/src


Ignore:
Timestamp:
09/22/20 16:26:36 (4 years ago)
Author:
bart
Message:

Minor fixes

Location:
protocol/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • protocol/src/main/java/geniusweb/protocol/session/mopac/MOPAC.java

    r21 r22  
    145145                        ProtocolToPartyConnFactory connectionfactory) {
    146146                try {
    147                         System.out.println("starting MOPAC");
     147                        //System.out.println("starting MOPAC");
    148148                        // we're in Phase.INIT still
    149149                        connect(connectionfactory);
     
    314314                        final ProtocolToPartyConn partyconn, final Action action,
    315315                        long now) {
    316                 System.out.println("received " + action);
     316                //System.out.println("received " + action);
    317317                state = state.with(partyconn.getParty(), action, now);
    318318                checkEndPhase(System.currentTimeMillis());
     
    341341
    342342                state = state.nextPhase(now);
     343
    343344                startPhase(now);
    344345        }
     
    351352         */
    352353        private void broadcastNegotiators(Inform info) {
    353                 System.out.println("broadcasting " + info);
     354                //System.out.println("broadcasting " + info);
    354355                for (PartyId party : state.getPhase().getPartyStates()
    355356                                .getNegotiatingParties()) {
  • protocol/src/main/java/geniusweb/protocol/session/mopac/MOPACState.java

    r21 r22  
    1414import geniusweb.actions.PartyId;
    1515import geniusweb.inform.Agreements;
     16import geniusweb.inform.OptIn;
    1617import geniusweb.progress.Progress;
    1718import geniusweb.progress.ProgressRounds;
     
    2223import geniusweb.protocol.session.SessionState;
    2324import geniusweb.protocol.session.mopac.phase.OfferPhase;
     25import geniusweb.protocol.session.mopac.phase.OptInPhase;
    2426import geniusweb.protocol.session.mopac.phase.Phase;
    2527import geniusweb.protocol.session.saop.SAOPSettings;
     
    127129        /**
    128130         * @param now current time ms since 1970
    129          * @return the max possible duration in ms of this phase. Maybe negative if
    130          *         ew are past deadline
     131         * @return the max possible duration in ms of the NEXT phase. Maybe 0 or
     132         *         negative if past deadline.
    131133         */
    132134        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;
    133138                return Math.min(progress.getTerminationTime().getTime() - now,
    134139                                Phase.PHASE_MAXTIME);
     
    196201                Phase newphase = phase.next(now,
    197202                                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;
    205217        }
    206218
     
    217229         */
    218230        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
    220233                                && getAvailablePhaseTime(now) > Phase.PHASE_MINTIME;
     234                // System.out.println("newstate possible:" + a);
     235                return a;
    221236        }
    222237
  • protocol/src/test/java/geniusweb/protocol/session/amop/AMOPSettingsTest.java

    r21 r22  
    9797        }
    9898
     99        @SuppressWarnings("unused")
    99100        @Test(expected = IllegalArgumentException.class)
    100101        public void constructorNoDeadlineTest() {
  • protocol/src/test/java/geniusweb/protocol/session/amop/AMOPStateTest.java

    r21 r22  
    172172        }
    173173
     174        @SuppressWarnings("unused")
    174175        @Test
    175176        public void constructWithNullConnection() {
     
    375376        @Test
    376377        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)));
    384386                // party 1,2,4 vote for A, party 1,2 vote for B, party 3,4 vote for C.
    385387                // the biggest vote is P,Q,S
     
    407409        public void testNextPhase() {
    408410                // 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)));
    416419                // party 1,2,4 vote for A, party 1,2 vote for B, party 3,4 vote for C.
    417420                // the biggest vote is P,Q,S
  • protocol/src/test/java/geniusweb/protocol/tournament/allpermutations/AllPermutationsSettingsTest.java

    r18 r22  
    6868                profile2 = new ProfileRef("profile2");
    6969                profile3 = new ProfileRef("profile3");
    70                 ProfileList profiles1 = new ProfileList(Arrays.asList(profile1));
    71                 ProfileList profiles2 = new ProfileList(Arrays.asList(profile2));
    72                 ProfileList profiles3 = 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));
    7373
    7474                List<ProfileList> profiles = Arrays.asList(profiles1, profiles2,
     
    137137        }
    138138
     139        @SuppressWarnings("unused")
    139140        @Test(expected = IllegalArgumentException.class)
    140141        public void testNullParties() {
     
    145146        }
    146147
     148        @SuppressWarnings("unused")
    147149        @Test(expected = IllegalArgumentException.class)
    148150        public void testNoParties() {
     
    153155        }
    154156
     157        @SuppressWarnings("unused")
    155158        @Test(expected = IllegalArgumentException.class)
    156159        public void testNullProfiles() {
     
    159162        }
    160163
     164        @SuppressWarnings("unused")
    161165        @Test(expected = IllegalArgumentException.class)
    162166        public void testInsufficientProfiles() {
     
    167171        }
    168172
     173        @SuppressWarnings("unused")
    169174        @Test(expected = IllegalArgumentException.class)
    170175        public void testNullSessionSettings() {
     
    175180        }
    176181
     182        @SuppressWarnings("unused")
    177183        @Test(expected = IllegalArgumentException.class)
    178184        public void testOnePartyPerSession() {
     
    189195        }
    190196
    191 //      @Test
    192 //      public void makeCobTest() throws URISyntaxException {
    193 //              // Check that the cob party gets profile without the query part
    194 //              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 
    206197}
Note: See TracChangeset for help on using the changeset viewer.