<commit_before>/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you 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 quarks.test.topology;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumMap;
import java.util.HashSet;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorCompletionService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicLong;

import org.junit.Ignore;
import org.junit.Test;

import quarks.topology.TSink;
import quarks.topology.TStream;
import quarks.topology.TWindow;
import quarks.topology.Topology;
import quarks.topology.tester.Condition;

@Ignore
public abstract class TStreamTest extends TopologyAbstractTest {

    @Test
    public void testAlias() throws Exception {

        Topology t = newTopology();

        TStream<String> s = t.strings("a", "b");
        assertEquals(null, s.getAlias());
        
        TStream<String> s2 = s.alias("sAlias");
        assertSame(s, s2);
        assertEquals("sAlias", s.getAlias());
        assertEquals(null, s.filter(tuple -> true).getAlias());
        try {
            s.alias("another");  // expect ISE - alias already set
            assertTrue(false);
        } catch (IllegalStateException e) {
            ; // expected
        }
        // test access at runtime
        s.peek(tuple -> {
            assertEquals("sAlias", s.getAlias());
        });

        // just verify that alias presence doesn't otherwise muck up things
        Condition<Long> tc = t.getTester().tupleCount(s, 2);
        Condition<List<String>> contents = t.getTester().streamContents(s, "a", "b");
        complete(t, tc);

        assertTrue(contents.valid());
    }

    @Test
    public void testTag() throws Exception {

        Topology t = newTopology();

        List<String> tags = new ArrayList<>(Arrays.asList("tag1", "tag2"));
        
        TStream<String> s = t.strings("a", "b");
        assertEquals(0, s.getTags().size());
        
        TStream<String> s2 = s.tag("tag1", "tag2");
        assertSame(s, s2);
        assertTrue("s.tags="+s.getTags(), s.getTags().containsAll(tags));
        assertEquals(0, s.filter(tuple -> true).getTags().size());
        tags.add("tag3");
        s.tag("tag3");
        assertTrue("s.tags="+s.getTags(), s.getTags().containsAll(tags));
        s.tag("tag3", "tag2", "tag1");  // ok to redundantly add
        assertTrue("s.tags="+s.getTags(), s.getTags().containsAll(tags));

        // test access at runtime
        s.peek(tuple -> {
            assertTrue("s.tags="+s.getTags(), s.getTags().containsAll(tags));
        });

        // just verify that tag presence doesn't otherwise muck up things
        Condition<Long> tc = t.getTester().tupleCount(s, 2);
        Condition<List<String>> contents = t.getTester().streamContents(s, "a", "b");
        complete(t, tc);

        assertTrue(contents.valid());
    }

    @Test
    public void testFilter() throws Exception {

        Topology t = newTopology();<commit_msg>fix unrelated test failure with DevelopmentProvider<commit_after>/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you 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 quarks.test.topology;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumMap;
import java.util.HashSet;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorCompletionService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicLong;

import org.junit.Ignore;
import org.junit.Test;

import quarks.topology.TSink;
import quarks.topology.TStream;
import quarks.topology.TWindow;
import quarks.topology.Topology;
import quarks.topology.tester.Condition;

@Ignore
public abstract class TStreamTest extends TopologyAbstractTest {

    @Test
    public void testAlias() throws Exception {

        Topology t = newTopology();

        TStream<String> s = t.strings("a", "b");
        assertEquals(null, s.getAlias());
        
        TStream<String> s2 = s.alias("sAlias");
        assertSame(s, s2);
        assertEquals("sAlias", s.getAlias());
        
        try {
            s.alias("another");  // expect ISE - alias already set
            assertTrue(false);
        } catch (IllegalStateException e) {
            ; // expected
        }
        
        // test access at runtime
        s2 = s.peek(tuple -> {
            assertEquals("sAlias", s.getAlias());
        }).filter(tuple -> true);

        // just verify that alias presence doesn't otherwise muck up things
        Condition<Long> tc = t.getTester().tupleCount(s2, 2);
        Condition<List<String>> contents = t.getTester().streamContents(s2, "a", "b");
        complete(t, tc);

        assertTrue("contents "+contents.getResult(), contents.valid());
    }

    @Test
    public void testTag() throws Exception {

        Topology t = newTopology();

        List<String> tags = new ArrayList<>(Arrays.asList("tag1", "tag2"));
        
        TStream<String> s = t.strings("a", "b");
        assertEquals(0, s.getTags().size());
        
        TStream<String> s2 = s.tag("tag1", "tag2");
        assertSame(s, s2);
        assertTrue("s.tags="+s.getTags(), s.getTags().containsAll(tags));
        
        tags.add("tag3");
        s.tag("tag3");
        assertTrue("s.tags="+s.getTags(), s.getTags().containsAll(tags));
        
        s.tag("tag3", "tag2", "tag1");  // ok to redundantly add
        assertTrue("s.tags="+s.getTags(), s.getTags().containsAll(tags));

        // test access at runtime
        s2 = s.peek(tuple -> {
            assertTrue("s.tags="+s.getTags(), s.getTags().containsAll(tags));
        }).filter(tuple -> true);

        // just verify that tag presence doesn't otherwise muck up things
        Condition<Long> tc = t.getTester().tupleCount(s2, 2);
        Condition<List<String>> contents = t.getTester().streamContents(s2, "a", "b");
        complete(t, tc);

        assertTrue("contents "+contents.getResult(), contents.valid());
    }

    @Test
    public void testFilter() throws Exception {

        Topology t = newTopology();
{'fraction_non_alphanumeric': 0.12272348529936912, 'fraction_numerical': 0.005594572074753006, 'mean_word_length': 3.186347782760339, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7058933', 'n_tokens_mistral': 2382, 'n_tokens_neox': 2356, 'n_words': 668}