<commit_before>/*
 * Copyright 2014 The LolDevs team (https://github.com/loldevs)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.boreeas.riotapi.rtmp;

import junit.framework.TestCase;
import lombok.SneakyThrows;
import lombok.extern.log4j.Log4j;
import net.boreeas.riotapi.QueueType;
import net.boreeas.riotapi.Season;
import net.boreeas.riotapi.Shard;
import net.boreeas.riotapi.com.riotgames.platform.game.GameMode;
import net.boreeas.riotapi.com.riotgames.platform.login.impl.ClientVersionMismatchException;
import net.boreeas.riotapi.com.riotgames.platform.matchmaking.GameQueueConfig;
import net.boreeas.riotapi.com.riotgames.platform.matchmaking.MatchMakerParams;
import net.boreeas.riotapi.com.riotgames.platform.matchmaking.SearchingForMatchNotification;
import net.boreeas.riotapi.com.riotgames.platform.summoner.SummonerSkillLevel;
import net.boreeas.riotapi.com.riotgames.platform.summoner.runes.SummonerRuneInventory;
import net.boreeas.riotapi.com.riotgames.platform.summoner.spellbook.RunePageBook;
import net.boreeas.riotapi.com.riotgames.team.dto.Team;
import net.boreeas.riotapi.loginqeue.LoginQueue;

import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.stream.Collectors;

@Log4j
public class RtmpClientTest extends TestCase {

    private static Properties testConfig = new Properties();;
    private static Shard shard = Shard.EUW;
    private static RtmpClient client;
    private static long summonerId;
    private static long accountId;
    private static AsyncMessageReceiver asyncMessageReceiver;

    @Log4j
    private static class AsyncMessageReceiver implements Consumer<AsyncMessageEvent> {

        private CountDownLatch asynMessageReceived = new CountDownLatch(1);

        public void accept(AsyncMessageEvent event) {
            asynMessageReceived.countDown();
        }
    }

    static {
        staticSetup(); // Because @BeforeClass apparently isn't working
    }

    @SneakyThrows
    public static void staticSetup() {

        testConfig.load(new InputStreamReader(new FileInputStream("testconfig.properties")));

        client = new DefaultRtmpClient(shard.prodUrl, Shard.RTMPS_PORT, true);
        asyncMessageReceiver = new AsyncMessageReceiver();
        client.addAsyncChannelListener(asyncMessageReceiver);
        //client = new DefaultRtmpClient("localhost", 2099, true);

        String user = testConfig.getProperty("user");
        String pass = testConfig.getProperty("pass");
        String authKey = new LoginQueue(shard).waitInQueue(user, pass).await().getToken();

        try {
            client.connect();
            client.authenticate(user, pass, authKey, "4.13.14_07_25_15_10");
        } catch (ClientVersionMismatchException ex) {
            log.info("Reconnecting with version " + ex.getCurrentVersion());
            client.authenticate(user, pass, new LoginQueue(shard).waitInQueue(user, pass).await().getToken(), ex.getCurrentVersion());
        }

        summonerId = client.getLoginDataPacket().getAllSummonerData().getSummoner().getSumId();
        accountId = client.getLoginDataPacket().getAllSummonerData().getSummoner().getAcctId();
    }

    public void testAsyncMessageReceived() throws InterruptedException {
        if (!asyncMessageReceiver.asynMessageReceived.await(2, TimeUnit.SECONDS)) {
            fail("No async message received");
        }
    }

    public void testGetAccountState() {
        client.accountService.getAccountState();
    }

    public void testGetMasteryBook() {
        client.bookService.getMasteryBook(summonerId);
    }

    public void testGetSpellBook() {
        RunePageBook book = client.bookService.getSpellBook(summonerId);
    }

    public void testSaveMasteryBook() {
        client.bookService.saveMasteryBook(client.bookService.getMasteryBook(summonerId));<commit_msg>Update rtmp to match new loginqueue<commit_after>/*
 * Copyright 2014 The LolDevs team (https://github.com/loldevs)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.boreeas.riotapi.rtmp;

import junit.framework.TestCase;
import lombok.SneakyThrows;
import lombok.extern.log4j.Log4j;
import net.boreeas.riotapi.QueueType;
import net.boreeas.riotapi.Season;
import net.boreeas.riotapi.Shard;
import net.boreeas.riotapi.com.riotgames.platform.game.GameMode;
import net.boreeas.riotapi.com.riotgames.platform.login.impl.ClientVersionMismatchException;
import net.boreeas.riotapi.com.riotgames.platform.matchmaking.GameQueueConfig;
import net.boreeas.riotapi.com.riotgames.platform.matchmaking.MatchMakerParams;
import net.boreeas.riotapi.com.riotgames.platform.matchmaking.SearchingForMatchNotification;
import net.boreeas.riotapi.com.riotgames.platform.summoner.SummonerSkillLevel;
import net.boreeas.riotapi.com.riotgames.platform.summoner.runes.SummonerRuneInventory;
import net.boreeas.riotapi.com.riotgames.platform.summoner.spellbook.RunePageBook;
import net.boreeas.riotapi.com.riotgames.team.dto.Team;
import net.boreeas.riotapi.loginqeue.LoginQueue;

import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.stream.Collectors;

@Log4j
public class RtmpClientTest extends TestCase {

    private static Properties testConfig = new Properties();;
    private static Shard shard = Shard.EUW;
    private static RtmpClient client;
    private static long summonerId;
    private static long accountId;
    private static AsyncMessageReceiver asyncMessageReceiver;

    @Log4j
    private static class AsyncMessageReceiver implements Consumer<AsyncMessageEvent> {

        private CountDownLatch asynMessageReceived = new CountDownLatch(1);

        public void accept(AsyncMessageEvent event) {
            asynMessageReceived.countDown();
        }
    }

    static {
        staticSetup(); // Because @BeforeClass apparently isn't working
    }

    @SneakyThrows
    public static void staticSetup() {

        testConfig.load(new InputStreamReader(new FileInputStream("testconfig.properties")));

        client = new DefaultRtmpClient(shard.prodUrl, Shard.RTMPS_PORT, true);
        asyncMessageReceiver = new AsyncMessageReceiver();
        client.addAsyncChannelListener(asyncMessageReceiver);
        //client = new DefaultRtmpClient("localhost", 2099, true);

        String user = testConfig.getProperty("user");
        String pass = testConfig.getProperty("pass");
        String authKey = new LoginQueue(shard).waitInQueue(user, pass).await();

        try {
            client.connect();
            client.authenticate(user, pass, authKey, "4.13.14_07_25_15_10");
        } catch (ClientVersionMismatchException ex) {
            log.info("Reconnecting with version " + ex.getCurrentVersion());
            client.authenticate(user, pass, new LoginQueue(shard).waitInQueue(user, pass).await(), ex.getCurrentVersion());
        }

        summonerId = client.getLoginDataPacket().getAllSummonerData().getSummoner().getSumId();
        accountId = client.getLoginDataPacket().getAllSummonerData().getSummoner().getAcctId();
    }

    public void testAsyncMessageReceived() throws InterruptedException {
        if (!asyncMessageReceiver.asynMessageReceived.await(2, TimeUnit.SECONDS)) {
            fail("No async message received");
        }
    }

    public void testGetAccountState() {
        client.accountService.getAccountState();
    }

    public void testGetMasteryBook() {
        client.bookService.getMasteryBook(summonerId);
    }

    public void testGetSpellBook() {
        RunePageBook book = client.bookService.getSpellBook(summonerId);
    }

    public void testSaveMasteryBook() {
        client.bookService.saveMasteryBook(client.bookService.getMasteryBook(summonerId));
{'fraction_non_alphanumeric': 0.09530112508272667, 'fraction_numerical': 0.006838738142510479, 'mean_word_length': 4.082399103139013, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '416964', 'n_tokens_mistral': 2734, 'n_tokens_neox': 2593, 'n_words': 560}