<commit_before>package de.lancom.systems.stomp.wire;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;

import java.util.UUID;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import de.lancom.systems.stomp.StompClient;
import de.lancom.systems.stomp.StompFrameHandler;
import de.lancom.systems.stomp.util.AsyncHolder;
import de.lancom.systems.stomp.util.Broker;
import de.lancom.systems.stomp.wire.frame.Frame;
import de.lancom.systems.stomp.wire.frame.ReceiptFrame;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

public class InputStreamTest {

    protected static final Broker BROKER = new Broker();
    protected static final StompClient CLIENT = new StompClient();

    private static final int HOLDER_TIMEOUT_SECONDS = 2;

    @BeforeClass
    public static void startBroker() throws Exception {
        BROKER.startBroker();
        CLIENT.start();
    }

    @AfterClass
    public static void stopBroker() throws Exception {
        CLIENT.stop();
        BROKER.stopBroker();
    }

    @Test
    public void sendMessage() throws Exception {
        final StompUrl url = createStompUrl("/topic/%s", UUID.randomUUID());
        final Future<StompFrameExchange> result = CLIENT.send(url, "Test");
        final StompFrameExchange exchange = result.get();

        assertThat(exchange, is(notNullValue()));
        assertThat(exchange.getResponse(), is(notNullValue()));
        assertThat(exchange.getResponse(), is(instanceOf(ReceiptFrame.class)));
    }

    @Test
    public void readQueue() throws Exception {
        final StompUrl url = createStompUrl("/topic/%s", UUID.randomUUID());
        final String subscriptionId = UUID.randomUUID().toString();
        final String message = UUID.randomUUID().toString();

        try {
            final AsyncHolder<String> holder = AsyncHolder.create();

            CLIENT.subscribe(url, subscriptionId, new StompFrameHandler() {
                @Override
                public void handle(final Frame frame) throws Exception {
                    holder.set(frame.getBodyAsString());
                }
            });

            final Future<StompFrameExchange> future = CLIENT.send(url, message);
            final StompFrameExchange exchange = future.get();

            assertThat(exchange, is(notNullValue()));
            assertThat(exchange.getResponse(), is(notNullValue()));
            assertThat(exchange.getResponse(), is(instanceOf(ReceiptFrame.class)));

            final String result = holder.get(HOLDER_TIMEOUT_SECONDS, TimeUnit.SECONDS);

            assertThat(result, is(notNullValue()));
            assertThat(result, is(equalTo(message)));
        } finally {
            CLIENT.unsubscribe(url, subscriptionId);
        }
    }
<commit_msg>fix typo in stomp url<commit_after>package de.lancom.systems.stomp.wire;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;

import java.util.UUID;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import de.lancom.systems.stomp.StompClient;
import de.lancom.systems.stomp.StompFrameHandler;
import de.lancom.systems.stomp.util.AsyncHolder;
import de.lancom.systems.stomp.util.Broker;
import de.lancom.systems.stomp.wire.frame.Frame;
import de.lancom.systems.stomp.wire.frame.ReceiptFrame;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

public class InputStreamTest {

    protected static final Broker BROKER = new Broker();
    protected static final StompClient CLIENT = new StompClient();

    private static final int HOLDER_TIMEOUT_SECONDS = 2;

    @BeforeClass
    public static void startBroker() throws Exception {
        BROKER.startBroker();
        CLIENT.start();
    }

    @AfterClass
    public static void stopBroker() throws Exception {
        CLIENT.stop();
        BROKER.stopBroker();
    }

    @Test
    public void sendMessage() throws Exception {
        final StompUrl url = createStompUrl("/topic/%s", UUID.randomUUID());
        final Future<StompFrameExchange> result = CLIENT.send(url, "Test");
        final StompFrameExchange exchange = result.get();

        assertThat(exchange, is(notNullValue()));
        assertThat(exchange.getResponse(), is(notNullValue()));
        assertThat(exchange.getResponse(), is(instanceOf(ReceiptFrame.class)));
    }

    @Test
    public void readQueue() throws Exception {
        final StompUrl url = createStompUrl("/queue/%s", UUID.randomUUID());
        final String subscriptionId = UUID.randomUUID().toString();
        final String message = UUID.randomUUID().toString();

        try {
            final AsyncHolder<String> holder = AsyncHolder.create();

            CLIENT.subscribe(url, subscriptionId, new StompFrameHandler() {
                @Override
                public void handle(final Frame frame) throws Exception {
                    holder.set(frame.getBodyAsString());
                }
            });

            final Future<StompFrameExchange> future = CLIENT.send(url, message);
            final StompFrameExchange exchange = future.get();

            assertThat(exchange, is(notNullValue()));
            assertThat(exchange.getResponse(), is(notNullValue()));
            assertThat(exchange.getResponse(), is(instanceOf(ReceiptFrame.class)));

            final String result = holder.get(HOLDER_TIMEOUT_SECONDS, TimeUnit.SECONDS);

            assertThat(result, is(notNullValue()));
            assertThat(result, is(equalTo(message)));
        } finally {
            CLIENT.unsubscribe(url, subscriptionId);
        }
    }

{'fraction_non_alphanumeric': 0.10847003682624708, 'fraction_numerical': 0.00033478406427854036, 'mean_word_length': 3.175401816911251, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '417118', 'n_tokens_mistral': 1725, 'n_tokens_neox': 1658, 'n_words': 348}