Changeset 18 for simplerunner
- Timestamp:
- 06/11/20 16:34:40 (4 years ago)
- Location:
- simplerunner
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
simplerunner/pom.xml
r14 r18 6 6 <groupId>geniusweb</groupId> 7 7 <artifactId>simplerunner</artifactId> 8 <version>1.4. 0</version>8 <version>1.4.1</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.10</jackson-2-version> 19 <geniusweb.version>1.4.1</geniusweb.version> 19 20 </properties> 20 21 … … 31 32 <groupId>geniusweb</groupId> 32 33 <artifactId>protocol</artifactId> 33 <version> 1.4.0</version>34 <version>${geniusweb.version}</version> 34 35 </dependency> 35 36 <dependency> 36 37 <groupId>geniusweb</groupId> 37 38 <artifactId>party</artifactId> 38 <version> 1.4.0</version>39 <version>${geniusweb.version}</version> 39 40 </dependency> 40 41 <dependency> 41 42 <groupId>geniusweb.exampleparties</groupId> 42 43 <artifactId>randomparty</artifactId> 43 <version>1.4.0</version> 44 <scope>test</scope> 44 <version>${geniusweb.version}</version> 45 <scope> 46 test 47 </scope> 45 48 </dependency> 46 49 <dependency> 47 50 <groupId>geniusweb.exampleparties</groupId> 48 51 <artifactId>comparebids</artifactId> 49 <version>1.4.0</version> 50 <scope>test</scope> 52 <version>${geniusweb.version}</version> 53 <scope> 54 test 55 </scope> 51 56 </dependency> 52 57 <dependency> 53 58 <groupId>geniusweb.exampleparties</groupId> 54 59 <artifactId>simpleshaop</artifactId> 55 <version>1.4.0</version> 56 <scope>test</scope> 60 <version>${geniusweb.version}</version> 61 <scope> 62 test 63 </scope> 57 64 </dependency> 58 65 -
simplerunner/src/main/java/geniusweb/simplerunner/NegoRunner.java
r10 r18 7 7 import java.util.logging.Level; 8 8 9 import com.fasterxml.jackson.core.JsonProcessingException; 9 10 import com.fasterxml.jackson.databind.ObjectMapper; 10 11 … … 13 14 import geniusweb.protocol.NegoProtocol; 14 15 import geniusweb.protocol.NegoSettings; 16 import geniusweb.protocol.NegoState; 15 17 import geniusweb.protocol.partyconnection.ProtocolToPartyConnFactory; 16 import tudelft.utilities.logging.ReportToLogger;17 18 import tudelft.utilities.logging.Reporter; 18 19 … … 27 28 private final NegoProtocol protocol; 28 29 private final ProtocolToPartyConnFactory connectionfactory; 29 pr ivatefinal Reporter log;30 protected final Reporter log; 30 31 private final static ObjectMapper jackson = new ObjectMapper(); 31 32 … … 55 56 56 57 protected void stop() { 57 if (protocol.getState().getError() != null) { 58 log.log(Level.WARNING, "protocol terminated abnormally", 59 protocol.getState().getError()); 60 } else { 61 log.log(Level.INFO, 62 "protocol ended normally: " + protocol.getState()); 58 Level level = protocol.getState().getError() == null ? Level.INFO 59 : Level.WARNING; 60 logFinal(level, protocol.getState()); 61 } 62 63 /** 64 * Separate so that we can intercept this when mocking, as this will crash 65 * on mocks 66 * 67 * @param level 68 * @param state 69 */ 70 protected void logFinal(Level level, NegoState state) { 71 try { 72 log.log(level, "protocol ended normally: " 73 + jackson.writeValueAsString(protocol.getState())); 74 } catch (JsonProcessingException e) { 75 e.printStackTrace(); 63 76 } 64 77 } … … 75 88 76 89 NegoRunner runner = new NegoRunner(settings, 77 new ClassPathConnectionFactory(), 78 new ReportToLogger("sessionrunner")); 90 new ClassPathConnectionFactory(), new StdOutReporter()); 79 91 runner.run(); 80 92 } … … 90 102 } 91 103 } 104 105 class StdOutReporter implements Reporter { 106 107 @Override 108 public void log(Level arg0, String arg1) { 109 System.out.println(arg0 + ":" + arg1); 110 } 111 112 @Override 113 public void log(Level arg0, String arg1, Throwable arg2) { 114 System.out.println(arg0 + ">" + arg1); 115 } 116 117 } -
simplerunner/src/test/java/geniusweb/simplerunner/SessionRunnerTest.java
r9 r18 17 17 18 18 import geniusweb.protocol.CurrentNegoState; 19 import geniusweb.protocol.NegoState; 19 20 import geniusweb.protocol.ProtocolException; 20 21 import geniusweb.protocol.partyconnection.ProtocolToPartyConnFactory; … … 22 23 import geniusweb.protocol.session.SessionSettings; 23 24 import geniusweb.protocol.session.SessionState; 24 import geniusweb.simplerunner.NegoRunner;25 25 import tudelft.utilities.listener.Listener; 26 26 import tudelft.utilities.logging.ReportToLogger; … … 59 59 ProtocolToPartyConnFactory.class); 60 60 61 NegoRunner runner = spy( 62 new NegoRunner(settings, factory, logger)); 61 NegoRunner runner = spy(new NegoRunner(settings, factory, logger)); 63 62 runner.run(); 64 63 … … 82 81 ProtocolToPartyConnFactory factory = mock( 83 82 ProtocolToPartyConnFactory.class); 84 NegoRunner runner = spy( 85 new NegoRunner(settings, factory, logger)); 83 NegoRunner runner = spy(new NegoRunner(settings, factory, logger) { 84 @Override 85 protected void logFinal(Level level, NegoState state) { 86 log.log(level, state.toString()); 87 } 88 }); 86 89 ArgumentCaptor<Listener> listener = ArgumentCaptor 87 90 .forClass(Listener.class); … … 109 112 ProtocolToPartyConnFactory factory = mock( 110 113 ProtocolToPartyConnFactory.class); 111 NegoRunner runner = spy( 112 new NegoRunner(settings, factory, logger)); 114 NegoRunner runner = spy(new NegoRunner(settings, factory, logger) { 115 @Override 116 protected void logFinal(Level level, NegoState state) { 117 log.log(level, state.toString()); 118 } 119 }); 113 120 ArgumentCaptor<Listener> listener = ArgumentCaptor 114 121 .forClass(Listener.class); … … 120 127 verify(runner, times(1)).stop(); 121 128 // check that the protocol error is logged properly 122 verify(logger, times(1)).log(eq(Level.WARNING), any(String.class), 123 eq(PROTOCOL_EXC)); 129 verify(logger, times(1)).log(eq(Level.WARNING), any(String.class)); 124 130 } 125 131 -
simplerunner/src/test/resources/settings2.json
r8 r18 13 13 } 14 14 } 15 15 16 } 16 17 } -
simplerunner/src/test/resources/shaoptoursettings.json
r14 r18 59 59 } 60 60 } 61 } 61 }, 62 "numberTournaments":1 62 63 } 63 64 }
Note:
See TracChangeset
for help on using the changeset viewer.