1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.processing.execution.test;
import com.yahoo.component.chain.Chain;
import com.yahoo.processing.Processor;
import com.yahoo.processing.Request;
import com.yahoo.processing.Response;
import com.yahoo.processing.execution.Execution;
import org.junit.Test;
import static com.yahoo.processing.test.ProcessorLibrary.*;
import static org.junit.Assert.assertEquals;
/**
* @author bratseth
*/
public class AsyncExecutionTestCase {
/** Execute a processing chain which forks off into multiple threads */
@Test
public void testAsyncExecution() {
// Create a chain
Chain<Processor> chain=new Chain<>(new CombineData(),new BlockingSplitter(2),new Get6DataItems(), new DataSource());
// Execute it
Request request=new Request();
request.properties().set("appendage",1);
Response response=Execution.createRoot(chain,0,Execution.Environment.createEmpty()).process(request);
// Verify the result
assertEquals(6*2-1,response.data().asList().size());
assertEquals("first.2, third.2",response.data().get(0).toString());
assertEquals("second.2",response.data().get(1).toString());
assertEquals("first.3",response.data().get(2).toString());
assertEquals("second.3",response.data().get(3).toString());
assertEquals("third.3",response.data().get(4).toString());
// from the parallel execution
assertEquals("first.2",response.data().get(5).toString());
assertEquals("second.2",response.data().get(6).toString());
assertEquals("third.2",response.data().get(7).toString());
assertEquals("first.3",response.data().get(8).toString());
assertEquals("second.3",response.data().get(9).toString());
assertEquals("third.3",response.data().get(10).toString());
}
}
|