<commit_before>package com.payu.discovery.tests;

import static com.jayway.awaitility.Awaitility.await;
import static org.assertj.core.api.Assertions.assertThat;

import com.payu.discovery.Discover;
import com.payu.discovery.client.EnableServiceDiscovery;
import com.payu.discovery.client.config.ServiceDiscoveryClientConfig;
import com.payu.discovery.server.DiscoveryServerMain;
import com.payu.discovery.server.InMemoryDiscoveryServer;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = {DiscoveryServerMain.class, LoadBalancingTest.class})
@IntegrationTest({
        "server.port:8060",
        "serviceDiscovery.address:http://localhost:8060/server/discovery"})
@WebAppConfiguration
@EnableServiceDiscovery
@PropertySource("classpath:propertasy.properties")
public class LoadBalancingTest {

    private List<ConfigurableApplicationContext> remoteContexts = new ArrayList<>();

    @Autowired
    private InMemoryDiscoveryServer server;

    @Discover
    private TestService testService;

    @Before
    public void before() throws InterruptedException {
        remoteContexts.add(SpringApplication.run(ServiceConfiguration.class,
                "--server.port=8031",
                "--app.address=http://localhost:8031",
                "--spring.jmx.enabled=false",
                "--serviceDiscovery.address=http://localhost:8060/server/discovery"));

        remoteContexts.add(SpringApplication.run(SecondServiceConfiguration.class,
                "--server.port=8032",
                "--app.address=http://localhost:8032",
                "--spring.jmx.enabled=false",
                "--serviceDiscovery.address=http://localhost:8060/server/discovery"));
    }

    @After
    public void close() {
        remoteContexts.forEach(context -> context.close());
    }

    @Configuration
    @EnableAutoConfiguration
    @Import(ServiceDiscoveryClientConfig.class)
    public static class ServiceConfiguration {

        @Bean
        public TestService testService() {
            return new TestServiceImpl();
        }

    }

    @Configuration
    @EnableAutoConfiguration
    @Import(ServiceDiscoveryClientConfig.class)
    public static class SecondServiceConfiguration {

        @Bean
        public TestService testService() {
            return new TestServiceImpl();
        }

    }

    @Test
    public void shouldLoadBalanceBetweenImplementations() throws InterruptedException {
        await().atMost(5, TimeUnit.SECONDS).until(() -> assertThat(server.fetchAllServices()).hasSize(2));<commit_msg>lambda -> Runnable (what a shame)<commit_after>package com.payu.discovery.tests;

import static com.jayway.awaitility.Awaitility.await;
import static org.assertj.core.api.Assertions.assertThat;

import com.payu.discovery.Discover;
import com.payu.discovery.client.EnableServiceDiscovery;
import com.payu.discovery.client.config.ServiceDiscoveryClientConfig;
import com.payu.discovery.server.DiscoveryServerMain;
import com.payu.discovery.server.InMemoryDiscoveryServer;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = {DiscoveryServerMain.class, LoadBalancingTest.class})
@IntegrationTest({
        "server.port:8060",
        "serviceDiscovery.address:http://localhost:8060/server/discovery"})
@WebAppConfiguration
@EnableServiceDiscovery
@PropertySource("classpath:propertasy.properties")
public class LoadBalancingTest {

    private List<ConfigurableApplicationContext> remoteContexts = new ArrayList<>();

    @Autowired
    private InMemoryDiscoveryServer server;

    @Discover
    private TestService testService;

    @Before
    public void before() throws InterruptedException {
        remoteContexts.add(SpringApplication.run(ServiceConfiguration.class,
                "--server.port=8031",
                "--app.address=http://localhost:8031",
                "--spring.jmx.enabled=false",
                "--serviceDiscovery.address=http://localhost:8060/server/discovery"));

        remoteContexts.add(SpringApplication.run(SecondServiceConfiguration.class,
                "--server.port=8032",
                "--app.address=http://localhost:8032",
                "--spring.jmx.enabled=false",
                "--serviceDiscovery.address=http://localhost:8060/server/discovery"));
    }

    @After
    public void close() {
        remoteContexts.forEach(context -> context.close());
    }

    @Configuration
    @EnableAutoConfiguration
    @Import(ServiceDiscoveryClientConfig.class)
    public static class ServiceConfiguration {

        @Bean
        public TestService testService() {
            return new TestServiceImpl();
        }

    }

    @Configuration
    @EnableAutoConfiguration
    @Import(ServiceDiscoveryClientConfig.class)
    public static class SecondServiceConfiguration {

        @Bean
        public TestService testService() {
            return new TestServiceImpl();
        }

    }

    @Test
    public void shouldLoadBalanceBetweenImplementations() throws InterruptedException {
        await().atMost(5, TimeUnit.SECONDS).until(
        		new Runnable() {
					
					@Override
					public void run() {
						assertThat(server.fetchAllServices()).hasSize(2);
					}
				});
        		
{'fraction_non_alphanumeric': 0.10094193729790524, 'fraction_numerical': 0.010403486573878814, 'mean_word_length': 4.006333567909922, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '2277036', 'n_tokens_mistral': 1927, 'n_tokens_neox': 1818, 'n_words': 291}