<commit_before>/*
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.xwiki.test.cluster;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.List;
import java.util.Properties;

import org.junit.runner.RunWith;
import org.xwiki.test.integration.XWikiExecutor;
import org.xwiki.test.integration.XWikiExecutorSuite;

/**
 * Runs all functional tests found in the classpath and start/stop XWiki before/after the tests (only once).
 *
 * @version $Id$
 */
@RunWith(XWikiExecutorSuite.class)
@XWikiExecutorSuite.Executors(2)
public class AllTests
{
    private static final String WEBINF_PATH = "/observation/remote/jgroups";

    @XWikiExecutorSuite.PreStart
    public void preInitialize(List<XWikiExecutor> executors) throws Exception
    {
        initChannel(executors.get(0), "tcp1");
        initChannel(executors.get(1), "tcp2");
    }

    private void initChannel(XWikiExecutor executor, String channelName) throws Exception
    {
        Properties properties = executor.loadXWikiProperties();
        properties.setProperty("observation.remote.enabled", "true");
        properties.setProperty("observation.remote.channels", channelName);
        executor.saveXWikiProperties(properties);

        String filename = channelName + ".xml";

        InputStream is = getClass().getResourceAsStream("/" + filename);
        try {
            FileOutputStream fos = new FileOutputStream(executor.getWebInfDirectory() + WEBINF_PATH + "/" + filename);

            byte[] buffer = new byte[1024];

            for (int nb; (nb = is.read(buffer)) > 0;) {
                fos.write(buffer, 0, nb);
            }
        } finally {
            is.close();
        }
    }
}<commit_msg>XWIKI-6718: Remote observation should fallback on JGroups embedded configurations Fix tests<commit_after>/*
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.xwiki.test.cluster;

import java.util.List;
import java.util.Properties;

import org.junit.runner.RunWith;
import org.xwiki.test.integration.XWikiExecutor;
import org.xwiki.test.integration.XWikiExecutorSuite;

/**
 * Runs all functional tests found in the classpath and start/stop XWiki before/after the tests (only once).
 * 
 * @version $Id$
 */
@RunWith(XWikiExecutorSuite.class)
@XWikiExecutorSuite.Executors(2)
public class AllTests
{
    @XWikiExecutorSuite.PreStart
    public void preInitialize(List<XWikiExecutor> executors) throws Exception
    {
        initChannel(executors.get(0), "tcp");
        initChannel(executors.get(1), "tcp");
    }

    private void initChannel(XWikiExecutor executor, String channelName) throws Exception
    {
        Properties properties = executor.loadXWikiProperties();
        properties.setProperty("observation.remote.enabled", "true");
        properties.setProperty("observation.remote.channels", channelName);
        executor.saveXWikiProperties(properties);

        // This is sometimes required sometime not depending on the system environment
        executor.addEnv("jgroups.bind_addr", "localhost");
    }
}
{'fraction_non_alphanumeric': 0.08820426250263769, 'fraction_numerical': 0.009284659210803967, 'mean_word_length': 3.7070506454816288, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 1}, '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': '7665804', 'n_tokens_mistral': 1299, 'n_tokens_neox': 1257, 'n_words': 459}