Changeset 18 for simplerunner/src
- Timestamp:
- 06/11/20 16:34:40 (4 years ago)
- Location:
- simplerunner/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
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.