/** * Creates a new store for configuration values. * * @param config the configuration to use. * */ public InMemoryMessageExchangeStore(final NetworkConfig config) { this(config, new InMemoryRandomTokenProvider(config)); LOGGER.log(Level.CONFIG, "using default TokenProvider {0}", InMemoryRandomTokenProvider.class.getName()); }
@Override public KeyToken getUnusedToken(final Message message) { return createUnusedToken(message); }
@Test public void testReceiveResponseForObserveDoesNotReleaseToken() { // GIVEN a request without token sent UdpMatcher matcher = newMatcher(false); Exchange exchange = sendObserveRequest(matcher); // WHEN observe request gets completed exchange.completeCurrentRequest(); // THEN assert that token got not released KeyToken keyToken = KeyToken.fromOutboundMessage(exchange.getCurrentRequest()); assertThat(tokenProvider.isTokenInUse(keyToken), is(true)); }
@Test public void testReceiveResponseReleasesToken() { // GIVEN a request without token sent UdpMatcher matcher = newMatcher(false); Exchange exchange = sendRequest(matcher, null); // WHEN request gets completed exchange.completeCurrentRequest(); // THEN assert that token got released KeyToken keyToken = KeyToken.fromOutboundMessage(exchange.getCurrentRequest()); assertThat(tokenProvider.isTokenInUse(keyToken), is(false)); }
@Before public void before(){ config = NetworkConfig.createStandardWithoutFile(); tokenProvider = new InMemoryRandomTokenProvider(config); messageExchangeStore = new InMemoryMessageExchangeStore(config, tokenProvider); }
private TcpMatcher newMatcher(boolean useStrictMatching) { NetworkConfig config = NetworkConfig.createStandardWithoutFile(); config.setBoolean(NetworkConfig.Keys.USE_STRICT_RESPONSE_MATCHING, useStrictMatching); TokenProvider tokenProvider = new InMemoryRandomTokenProvider(config); MessageExchangeStore messageExchangeStore = new InMemoryMessageExchangeStore(config, tokenProvider); TcpMatcher matcher = new TcpMatcher(config, messageExchangeStore); matcher.start(); return matcher; }