<commit_before>package io.muoncore.extension.amqp.externalbroker

import io.muoncore.channel.ChannelConnection
import io.muoncore.codec.GsonCodec
import io.muoncore.extension.amqp.AMQPMuonTransport
import io.muoncore.extension.amqp.DefaultAmqpChannelFactory
import io.muoncore.extension.amqp.DefaultServiceQueue
import io.muoncore.extension.amqp.rabbitmq09.RabbitMq09ClientAmqpConnection
import io.muoncore.extension.amqp.rabbitmq09.RabbitMq09QueueListenerFactory
import io.muoncore.protocol.ServerStacks
import io.muoncore.protocol.requestresponse.RRPTransformers
import io.muoncore.transport.TransportOutboundMessage
import spock.lang.Specification

class EstablishChannelSpec extends Specification {

    def serverStacks1 = Mock(ServerStacks)
    def serverStacks2 = Mock(ServerStacks)

    def "two transports can establish an AMQP channel between them"() {

        AMQPMuonTransport svc1 = createTransport("service1", serverStacks1)
        AMQPMuonTransport svc2 = createTransport("tombola", serverStacks2)

        svc2.start()
        svc1.start()

        when:
        def channel = svc1.openClientChannel("tombola", "requestresponse")

        channel.send(new TransportOutboundMessage(
                "1",
                "tombola",
                RRPTransformers.REQUEST_RESPONSE_PROTOCOL,
                [:],
                "applicaton/json",
                new GsonCodec().encode([:])))
        sleep(50)

        then:
        1 * serverStacks2.openServerChannel("requestresponse") >> Mock(ChannelConnection)
    }

    private AMQPMuonTransport createTransport(serviceName, serverStacks) {

        def connection = new RabbitMq09ClientAmqpConnection("amqp://muon:microservices@localhost")<commit_msg>Add event type param<commit_after>package io.muoncore.extension.amqp.externalbroker

import io.muoncore.channel.ChannelConnection
import io.muoncore.codec.GsonCodec
import io.muoncore.extension.amqp.AMQPMuonTransport
import io.muoncore.extension.amqp.DefaultAmqpChannelFactory
import io.muoncore.extension.amqp.DefaultServiceQueue
import io.muoncore.extension.amqp.rabbitmq09.RabbitMq09ClientAmqpConnection
import io.muoncore.extension.amqp.rabbitmq09.RabbitMq09QueueListenerFactory
import io.muoncore.protocol.ServerStacks
import io.muoncore.protocol.requestresponse.RRPTransformers
import io.muoncore.transport.TransportOutboundMessage
import spock.lang.Specification

class EstablishChannelSpec extends Specification {

    def serverStacks1 = Mock(ServerStacks)
    def serverStacks2 = Mock(ServerStacks)

    def "two transports can establish an AMQP channel between them"() {

        AMQPMuonTransport svc1 = createTransport("service1", serverStacks1)
        AMQPMuonTransport svc2 = createTransport("tombola", serverStacks2)

        svc2.start()
        svc1.start()

        when:
        def channel = svc1.openClientChannel("tombola", "requestresponse")

        channel.send(new TransportOutboundMessage(
                "somethingHappened",
                "1",
                "tombola",
                RRPTransformers.REQUEST_RESPONSE_PROTOCOL,
                [:],
                "applicaton/json",
                new GsonCodec().encode([:])))
        sleep(50)

        then:
        1 * serverStacks2.openServerChannel("requestresponse") >> Mock(ChannelConnection)
    }

    private AMQPMuonTransport createTransport(serviceName, serverStacks) {

        def connection = new RabbitMq09ClientAmqpConnection("amqp://muon:microservices@localhost")
{'fraction_non_alphanumeric': 0.08328563251287922, 'fraction_numerical': 0.014310246136233544, 'mean_word_length': 3.7039030955585464, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '3878708', 'n_tokens_mistral': 1067, 'n_tokens_neox': 1009, 'n_words': 163}