| 1 | package fr.sii.ogham.testing.sms.simulator.jsmpp; | |
| 2 | ||
| 3 | import static fr.sii.ogham.testing.sms.simulator.decode.MessageDecoder.decode; | |
| 4 | import static java.util.Collections.unmodifiableList; | |
| 5 | import static org.jsmpp.bean.SMSCDeliveryReceipt.SUCCESS_FAILURE; | |
| 6 | ||
| 7 | import java.io.IOException; | |
| 8 | import java.util.ArrayList; | |
| 9 | import java.util.List; | |
| 10 | import java.util.concurrent.ExecutorService; | |
| 11 | import java.util.concurrent.Executors; | |
| 12 | ||
| 13 | import org.jsmpp.bean.CancelSm; | |
| 14 | import org.jsmpp.bean.DataSm; | |
| 15 | import org.jsmpp.bean.QuerySm; | |
| 16 | import org.jsmpp.bean.ReplaceSm; | |
| 17 | import org.jsmpp.bean.SubmitMulti; | |
| 18 | import org.jsmpp.bean.SubmitMultiResult; | |
| 19 | import org.jsmpp.bean.SubmitSm; | |
| 20 | import org.jsmpp.extra.ProcessRequestException; | |
| 21 | import org.jsmpp.session.DataSmResult; | |
| 22 | import org.jsmpp.session.QuerySmResult; | |
| 23 | import org.jsmpp.session.SMPPServerSession; | |
| 24 | import org.jsmpp.session.SMPPServerSessionListener; | |
| 25 | import org.jsmpp.session.ServerMessageReceiverListener; | |
| 26 | import org.jsmpp.session.ServerResponseDeliveryAdapter; | |
| 27 | import org.jsmpp.session.Session; | |
| 28 | import org.jsmpp.util.MessageIDGenerator; | |
| 29 | import org.jsmpp.util.MessageId; | |
| 30 | import org.slf4j.Logger; | |
| 31 | import org.slf4j.LoggerFactory; | |
| 32 | ||
| 33 | import fr.sii.ogham.testing.sms.simulator.config.SimulatorConfiguration; | |
| 34 | ||
| 35 | /** | |
| 36 | * @author uudashr | |
| 37 | * @author Aurélien Baudet | |
| 38 | * | |
| 39 | */ | |
| 40 | public class JSMPPServerSimulator extends ServerResponseDeliveryAdapter implements Runnable, ServerMessageReceiverListener { | |
| 41 | private static final int BIND_THREAD_POOL_SIZE = 5; | |
| 42 | private static final int RECEIPT_THREAD_POOL_SIZE = 100; | |
| 43 | ||
| 44 | private static final Logger LOG = LoggerFactory.getLogger(JSMPPServerSimulator.class); | |
| 45 | ||
| 46 | private ExecutorService execService; | |
| 47 | private final ExecutorService execServiceDelReceipt = Executors.newFixedThreadPool(RECEIPT_THREAD_POOL_SIZE); | |
| 48 | private final MessageIDGenerator messageIDGenerator = new UnsecureRandomMessageIDGenerator(); | |
| 49 | private int port; | |
| 50 | private boolean stopped; | |
| 51 | private List<SubmitSm> receivedMessages = new ArrayList<>(); | |
| 52 | private SMPPServerSessionListener sessionListener; | |
| 53 | private SMPPServerSession serverSession; | |
| 54 | private final Object startupMonitor = new Object(); | |
| 55 | private volatile boolean running = false; | |
| 56 | private final SimulatorConfiguration config; | |
| 57 | private ServerStartupException startupFailure; | |
| 58 | ||
| 59 | public JSMPPServerSimulator(int port, SimulatorConfiguration config) { | |
| 60 | this.port = port; | |
| 61 | this.config = config; | |
| 62 | } | |
| 63 | ||
| 64 | public void run() { | |
| 65 | try { | |
| 66 |
2
1. run : negated conditional → NO_COVERAGE 2. run : negated conditional → TIMED_OUT |
if (!stopped) { |
| 67 | sessionListener = createServerSessionListener(); | |
| 68 | execService = Executors.newFixedThreadPool(BIND_THREAD_POOL_SIZE); | |
| 69 | running = true; | |
| 70 | LOG.info("Listening on port {}", port); | |
| 71 | synchronized (startupMonitor) { | |
| 72 |
2
1. run : removed call to java/lang/Object::notifyAll → NO_COVERAGE 2. run : removed call to java/lang/Object::notifyAll → TIMED_OUT |
startupMonitor.notifyAll(); |
| 73 | } | |
| 74 | } | |
| 75 |
3
1. run : negated conditional → NO_COVERAGE 2. run : negated conditional → SURVIVED 3. run : negated conditional → TIMED_OUT |
while (!stopped) { |
| 76 | serverSession = sessionListener.accept(); | |
| 77 | LOG.info("Accepting connection for session {}", serverSession.getSessionId()); | |
| 78 |
5
1. run : removed call to org/jsmpp/session/SMPPServerSession::setMessageReceiverListener → NO_COVERAGE 2. run : removed call to org/jsmpp/session/SMPPServerSession::setMessageReceiverListener → TIMED_OUT 3. run : removed call to org/jsmpp/session/SMPPServerSession::setMessageReceiverListener → KILLED 4. run : removed call to org/jsmpp/session/SMPPServerSession::setMessageReceiverListener → KILLED 5. run : removed call to org/jsmpp/session/SMPPServerSession::setMessageReceiverListener → KILLED |
serverSession.setMessageReceiverListener(this); |
| 79 |
3
1. run : removed call to org/jsmpp/session/SMPPServerSession::setResponseDeliveryListener → SURVIVED 2. run : removed call to org/jsmpp/session/SMPPServerSession::setResponseDeliveryListener → NO_COVERAGE 3. run : removed call to org/jsmpp/session/SMPPServerSession::setResponseDeliveryListener → TIMED_OUT |
serverSession.setResponseDeliveryListener(this); |
| 80 |
2
1. run : removed call to java/util/concurrent/ExecutorService::execute → NO_COVERAGE 2. run : removed call to java/util/concurrent/ExecutorService::execute → TIMED_OUT |
execService.execute(new WaitBindTask(serverSession, config.getCredentials())); |
| 81 | } | |
| 82 | } catch (IOException e) { | |
| 83 |
4
1. run : negated conditional → SURVIVED 2. run : negated conditional → NO_COVERAGE 3. run : negated conditional → TIMED_OUT 4. run : negated conditional → KILLED |
if (!stopped) { // NOSONAR |
| 84 | LOG.trace("Failed to initialize SMPP server simulator", e); | |
| 85 | startupFailure = new ServerStartupException("Server failed to start on port "+port, e); | |
| 86 |
2
1. run : removed call to fr/sii/ogham/testing/sms/simulator/jsmpp/JSMPPServerSimulator::close → NO_COVERAGE 2. run : removed call to fr/sii/ogham/testing/sms/simulator/jsmpp/JSMPPServerSimulator::close → SURVIVED |
close(); |
| 87 | } | |
| 88 | } finally { | |
| 89 | // Notify everybody that we're ready to accept connections or failed | |
| 90 | // to start. | |
| 91 | // Otherwise will run into startup timeout, see | |
| 92 | // #waitTillRunning(long). | |
| 93 | synchronized (startupMonitor) { | |
| 94 |
3
1. run : removed call to java/lang/Object::notifyAll → SURVIVED 2. run : removed call to java/lang/Object::notifyAll → NO_COVERAGE 3. run : removed call to java/lang/Object::notifyAll → TIMED_OUT |
startupMonitor.notifyAll(); |
| 95 | } | |
| 96 | } | |
| 97 | } | |
| 98 | ||
| 99 | private SMPPServerSessionListener createServerSessionListener() throws IOException { | |
| 100 |
3
1. createServerSessionListener : replaced return value with null for fr/sii/ogham/testing/sms/simulator/jsmpp/JSMPPServerSimulator::createServerSessionListener → SURVIVED 2. createServerSessionListener : replaced return value with null for fr/sii/ogham/testing/sms/simulator/jsmpp/JSMPPServerSimulator::createServerSessionListener → NO_COVERAGE 3. createServerSessionListener : replaced return value with null for fr/sii/ogham/testing/sms/simulator/jsmpp/JSMPPServerSimulator::createServerSessionListener → TIMED_OUT |
return new ConfigurableSMPPServerSessionListener(port, config.getServerDelays()); |
| 101 | } | |
| 102 | ||
| 103 | public synchronized void reset() { | |
| 104 | stopped = false; | |
| 105 |
4
1. reset : negated conditional → SURVIVED 2. reset : negated conditional → NO_COVERAGE 3. reset : negated conditional → TIMED_OUT 4. reset : negated conditional → KILLED |
if (!config.isKeepMessages()) { |
| 106 |
4
1. reset : removed call to java/util/List::clear → NO_COVERAGE 2. reset : removed call to java/util/List::clear → SURVIVED 3. reset : removed call to java/util/List::clear → TIMED_OUT 4. reset : removed call to java/util/List::clear → KILLED |
receivedMessages.clear(); |
| 107 | } | |
| 108 | } | |
| 109 | ||
| 110 | public synchronized void stop() { | |
| 111 | LOG.info("Stopping SMPP simulator"); | |
| 112 | running = false; | |
| 113 | stopped = true; | |
| 114 |
4
1. stop : negated conditional → SURVIVED 2. stop : negated conditional → NO_COVERAGE 3. stop : negated conditional → TIMED_OUT 4. stop : negated conditional → KILLED |
if (execService != null) { |
| 115 | LOG.trace("Stopping executor service"); | |
| 116 | execService.shutdownNow(); | |
| 117 | execService = null; | |
| 118 | } | |
| 119 |
2
1. stop : removed call to fr/sii/ogham/testing/sms/simulator/jsmpp/JSMPPServerSimulator::close → NO_COVERAGE 2. stop : removed call to fr/sii/ogham/testing/sms/simulator/jsmpp/JSMPPServerSimulator::close → TIMED_OUT |
close(); |
| 120 | LOG.info("SMPP simulator stopped"); | |
| 121 | } | |
| 122 | ||
| 123 | private void close() { | |
| 124 |
6
1. close : negated conditional → NO_COVERAGE 2. close : negated conditional → TIMED_OUT 3. close : negated conditional → KILLED 4. close : negated conditional → KILLED 5. close : negated conditional → KILLED 6. close : negated conditional → KILLED |
if (serverSession != null) { |
| 125 | LOG.trace("Closing server session"); | |
| 126 |
4
1. close : removed call to org/jsmpp/session/SMPPServerSession::close → SURVIVED 2. close : removed call to org/jsmpp/session/SMPPServerSession::close → NO_COVERAGE 3. close : removed call to org/jsmpp/session/SMPPServerSession::close → TIMED_OUT 4. close : removed call to org/jsmpp/session/SMPPServerSession::close → KILLED |
serverSession.close(); |
| 127 | LOG.trace("Server session closed"); | |
| 128 | serverSession = null; | |
| 129 | } | |
| 130 |
3
1. close : negated conditional → NO_COVERAGE 2. close : negated conditional → TIMED_OUT 3. close : negated conditional → KILLED |
if (sessionListener != null) { |
| 131 | try { | |
| 132 | LOG.trace("Closing session listener"); | |
| 133 |
2
1. close : removed call to org/jsmpp/session/SMPPServerSessionListener::close → NO_COVERAGE 2. close : removed call to org/jsmpp/session/SMPPServerSessionListener::close → TIMED_OUT |
sessionListener.close(); |
| 134 | LOG.trace("Session listener closed"); | |
| 135 | sessionListener = null; | |
| 136 | } catch (IOException e) { | |
| 137 | // nothing to do | |
| 138 | LOG.trace("Failed to close session listener", e); | |
| 139 | } | |
| 140 | } | |
| 141 | } | |
| 142 | ||
| 143 | public void waitTillRunning(long timeoutInMs) throws ServerStartupException { | |
| 144 | try { | |
| 145 | long t = System.currentTimeMillis(); | |
| 146 | synchronized (startupMonitor) { | |
| 147 | // Loop to avoid spurious wake ups, see | |
| 148 | // https://www.securecoding.cert.org/confluence/display/java/THI03-J.+Always+invoke+wait%28%29+and+await%28%29+methods+inside+a+loop | |
| 149 |
27
1. waitTillRunning : changed conditional boundary → NO_COVERAGE 2. waitTillRunning : changed conditional boundary → SURVIVED 3. waitTillRunning : Replaced long subtraction with addition → NO_COVERAGE 4. waitTillRunning : negated conditional → NO_COVERAGE 5. waitTillRunning : negated conditional → NO_COVERAGE 6. waitTillRunning : negated conditional → NO_COVERAGE 7. waitTillRunning : changed conditional boundary → TIMED_OUT 8. waitTillRunning : Replaced long subtraction with addition → TIMED_OUT 9. waitTillRunning : negated conditional → TIMED_OUT 10. waitTillRunning : negated conditional → TIMED_OUT 11. waitTillRunning : negated conditional → TIMED_OUT 12. waitTillRunning : Replaced long subtraction with addition → KILLED 13. waitTillRunning : Replaced long subtraction with addition → KILLED 14. waitTillRunning : Replaced long subtraction with addition → KILLED 15. waitTillRunning : Replaced long subtraction with addition → KILLED 16. waitTillRunning : negated conditional → KILLED 17. waitTillRunning : negated conditional → KILLED 18. waitTillRunning : negated conditional → KILLED 19. waitTillRunning : negated conditional → KILLED 20. waitTillRunning : negated conditional → KILLED 21. waitTillRunning : negated conditional → KILLED 22. waitTillRunning : negated conditional → KILLED 23. waitTillRunning : negated conditional → KILLED 24. waitTillRunning : negated conditional → KILLED 25. waitTillRunning : negated conditional → KILLED 26. waitTillRunning : negated conditional → KILLED 27. waitTillRunning : negated conditional → KILLED |
while (!running && startupFailure == null && System.currentTimeMillis() - t < timeoutInMs) { |
| 150 |
3
1. waitTillRunning : removed call to java/lang/Object::wait → NO_COVERAGE 2. waitTillRunning : removed call to java/lang/Object::wait → SURVIVED 3. waitTillRunning : removed call to java/lang/Object::wait → TIMED_OUT |
startupMonitor.wait(timeoutInMs); |
| 151 | } | |
| 152 | } | |
| 153 | } catch (InterruptedException e) { | |
| 154 |
1
1. waitTillRunning : removed call to java/lang/Thread::interrupt → NO_COVERAGE |
Thread.currentThread().interrupt(); |
| 155 | throw new ServerStartupException("Server failed to start (interrupted)", e); | |
| 156 | } | |
| 157 | | |
| 158 |
6
1. waitTillRunning : negated conditional → NO_COVERAGE 2. waitTillRunning : negated conditional → TIMED_OUT 3. waitTillRunning : negated conditional → KILLED 4. waitTillRunning : negated conditional → KILLED 5. waitTillRunning : negated conditional → KILLED 6. waitTillRunning : negated conditional → KILLED |
if (startupFailure != null) { |
| 159 | throw startupFailure; | |
| 160 | } | |
| 161 | ||
| 162 |
6
1. waitTillRunning : negated conditional → NO_COVERAGE 2. waitTillRunning : negated conditional → TIMED_OUT 3. waitTillRunning : negated conditional → KILLED 4. waitTillRunning : negated conditional → KILLED 5. waitTillRunning : negated conditional → KILLED 6. waitTillRunning : negated conditional → KILLED |
if (!running) { |
| 163 |
1
1. waitTillRunning : removed call to fr/sii/ogham/testing/sms/simulator/jsmpp/JSMPPServerSimulator::close → NO_COVERAGE |
close(); |
| 164 | throw new ServerStartupException("Server bouldn't be started after "+timeoutInMs+"ms"); | |
| 165 | } | |
| 166 | } | |
| 167 | ||
| 168 | public QuerySmResult onAcceptQuerySm(QuerySm querySm, SMPPServerSession source) throws ProcessRequestException { | |
| 169 | LOG.info("Accepting query sm, but not implemented"); | |
| 170 | return null; | |
| 171 | } | |
| 172 | ||
| 173 | public MessageId onAcceptSubmitSm(SubmitSm submitSm, SMPPServerSession source) throws ProcessRequestException { | |
| 174 | MessageId messageId = messageIDGenerator.newMessageId(); | |
| 175 | if (LOG.isDebugEnabled()) { | |
| 176 | LOG.debug("Receiving submit_sm '{}', and return message id {}", decode(new SubmitSmAdapter(submitSm)), messageId); | |
| 177 | } | |
| 178 | receivedMessages.add(submitSm); | |
| 179 |
3
1. onAcceptSubmitSm : negated conditional → SURVIVED 2. onAcceptSubmitSm : negated conditional → NO_COVERAGE 3. onAcceptSubmitSm : negated conditional → TIMED_OUT |
if (SUCCESS_FAILURE.containedIn(submitSm.getRegisteredDelivery())) { |
| 180 |
2
1. onAcceptSubmitSm : removed call to java/util/concurrent/ExecutorService::execute → NO_COVERAGE 2. onAcceptSubmitSm : removed call to java/util/concurrent/ExecutorService::execute → TIMED_OUT |
execServiceDelReceipt.execute(new DeliveryReceiptTask(source, submitSm, messageId)); |
| 181 | } | |
| 182 |
5
1. onAcceptSubmitSm : replaced return value with null for fr/sii/ogham/testing/sms/simulator/jsmpp/JSMPPServerSimulator::onAcceptSubmitSm → SURVIVED 2. onAcceptSubmitSm : replaced return value with null for fr/sii/ogham/testing/sms/simulator/jsmpp/JSMPPServerSimulator::onAcceptSubmitSm → NO_COVERAGE 3. onAcceptSubmitSm : replaced return value with null for fr/sii/ogham/testing/sms/simulator/jsmpp/JSMPPServerSimulator::onAcceptSubmitSm → TIMED_OUT 4. onAcceptSubmitSm : replaced return value with null for fr/sii/ogham/testing/sms/simulator/jsmpp/JSMPPServerSimulator::onAcceptSubmitSm → KILLED 5. onAcceptSubmitSm : replaced return value with null for fr/sii/ogham/testing/sms/simulator/jsmpp/JSMPPServerSimulator::onAcceptSubmitSm → KILLED |
return messageId; |
| 183 | } | |
| 184 | ||
| 185 | @Override | |
| 186 | public void onSubmitSmRespSent(MessageId messageId, SMPPServerSession source) { | |
| 187 | LOG.debug("submit_sm_resp with message_id {} has been sent", messageId); | |
| 188 | } | |
| 189 | ||
| 190 | public SubmitMultiResult onAcceptSubmitMulti(SubmitMulti submitMulti, SMPPServerSession source) throws ProcessRequestException { | |
| 191 | MessageId messageId = messageIDGenerator.newMessageId(); | |
| 192 | if (LOG.isDebugEnabled()) { | |
| 193 | LOG.debug("Receiving submit_multi_sm '{}', and return message id {}", submitMulti, messageId); | |
| 194 | } | |
| 195 |
1
1. onAcceptSubmitMulti : negated conditional → NO_COVERAGE |
if (SUCCESS_FAILURE.containedIn(submitMulti.getRegisteredDelivery())) { |
| 196 |
1
1. onAcceptSubmitMulti : removed call to java/util/concurrent/ExecutorService::execute → NO_COVERAGE |
execServiceDelReceipt.execute(new DeliveryReceiptTask(source, submitMulti, messageId)); |
| 197 | } | |
| 198 | ||
| 199 |
1
1. onAcceptSubmitMulti : replaced return value with null for fr/sii/ogham/testing/sms/simulator/jsmpp/JSMPPServerSimulator::onAcceptSubmitMulti → NO_COVERAGE |
return new SubmitMultiResult(messageId.getValue()); |
| 200 | } | |
| 201 | ||
| 202 | public DataSmResult onAcceptDataSm(DataSm dataSm, Session source) throws ProcessRequestException { | |
| 203 | LOG.debug("onAcceptDataSm '{}'", dataSm); | |
| 204 | return null; | |
| 205 | } | |
| 206 | ||
| 207 | @Override | |
| 208 | public void onAcceptCancelSm(CancelSm cancelSm, SMPPServerSession source) throws ProcessRequestException { | |
| 209 | // nothing to do | |
| 210 | } | |
| 211 | ||
| 212 | @Override | |
| 213 | public void onAcceptReplaceSm(ReplaceSm replaceSm, SMPPServerSession source) throws ProcessRequestException { | |
| 214 | // nothing to do | |
| 215 | } | |
| 216 | ||
| 217 | public List<SubmitSm> getReceivedMessages() { | |
| 218 |
5
1. getReceivedMessages : replaced return value with Collections.emptyList for fr/sii/ogham/testing/sms/simulator/jsmpp/JSMPPServerSimulator::getReceivedMessages → NO_COVERAGE 2. getReceivedMessages : replaced return value with Collections.emptyList for fr/sii/ogham/testing/sms/simulator/jsmpp/JSMPPServerSimulator::getReceivedMessages → TIMED_OUT 3. getReceivedMessages : replaced return value with Collections.emptyList for fr/sii/ogham/testing/sms/simulator/jsmpp/JSMPPServerSimulator::getReceivedMessages → KILLED 4. getReceivedMessages : replaced return value with Collections.emptyList for fr/sii/ogham/testing/sms/simulator/jsmpp/JSMPPServerSimulator::getReceivedMessages → KILLED 5. getReceivedMessages : replaced return value with Collections.emptyList for fr/sii/ogham/testing/sms/simulator/jsmpp/JSMPPServerSimulator::getReceivedMessages → KILLED |
return unmodifiableList(new ArrayList<>(receivedMessages)); |
| 219 | } | |
| 220 | ||
| 221 | public int getPort() { | |
| 222 |
6
1. getPort : replaced int return with 0 for fr/sii/ogham/testing/sms/simulator/jsmpp/JSMPPServerSimulator::getPort → SURVIVED 2. getPort : replaced int return with 0 for fr/sii/ogham/testing/sms/simulator/jsmpp/JSMPPServerSimulator::getPort → NO_COVERAGE 3. getPort : replaced int return with 0 for fr/sii/ogham/testing/sms/simulator/jsmpp/JSMPPServerSimulator::getPort → TIMED_OUT 4. getPort : replaced int return with 0 for fr/sii/ogham/testing/sms/simulator/jsmpp/JSMPPServerSimulator::getPort → KILLED 5. getPort : replaced int return with 0 for fr/sii/ogham/testing/sms/simulator/jsmpp/JSMPPServerSimulator::getPort → KILLED 6. getPort : replaced int return with 0 for fr/sii/ogham/testing/sms/simulator/jsmpp/JSMPPServerSimulator::getPort → KILLED |
return port; |
| 223 | } | |
| 224 | } | |
Mutations | ||
| 66 |
1.1 2.2 |
|
| 72 |
1.1 2.2 |
|
| 75 |
1.1 2.2 3.3 |
|
| 78 |
1.1 2.2 3.3 4.4 5.5 |
|
| 79 |
1.1 2.2 3.3 |
|
| 80 |
1.1 2.2 |
|
| 83 |
1.1 2.2 3.3 4.4 |
|
| 86 |
1.1 2.2 |
|
| 94 |
1.1 2.2 3.3 |
|
| 100 |
1.1 2.2 3.3 |
|
| 105 |
1.1 2.2 3.3 4.4 |
|
| 106 |
1.1 2.2 3.3 4.4 |
|
| 114 |
1.1 2.2 3.3 4.4 |
|
| 119 |
1.1 2.2 |
|
| 124 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
| 126 |
1.1 2.2 3.3 4.4 |
|
| 130 |
1.1 2.2 3.3 |
|
| 133 |
1.1 2.2 |
|
| 149 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9 10.10 11.11 12.12 13.13 14.14 15.15 16.16 17.17 18.18 19.19 20.20 21.21 22.22 23.23 24.24 25.25 26.26 27.27 |
|
| 150 |
1.1 2.2 3.3 |
|
| 154 |
1.1 |
|
| 158 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
| 162 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
| 163 |
1.1 |
|
| 179 |
1.1 2.2 3.3 |
|
| 180 |
1.1 2.2 |
|
| 182 |
1.1 2.2 3.3 4.4 5.5 |
|
| 195 |
1.1 |
|
| 196 |
1.1 |
|
| 199 |
1.1 |
|
| 218 |
1.1 2.2 3.3 4.4 5.5 |
|
| 222 |
1.1 2.2 3.3 4.4 5.5 6.6 |