OSDN Git Service

imported from subversion repository
[xerial/xerial-core.git] / src / test / java / org / xerial / lens / relation / query / StreamAmoebaJoinTest.java
1 /*--------------------------------------------------------------------------\r
2  *  Copyright 2009 Taro L. Saito\r
3  *\r
4  *  Licensed under the Apache License, Version 2.0 (the "License");\r
5  *  you may not use this file except in compliance with the License.\r
6  *  You may obtain a copy of the License at\r
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  *  Unless required by applicable law or agreed to in writing, software\r
11  *  distributed under the License is distributed on an "AS IS" BASIS,\r
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  *  See the License for the specific language governing permissions and\r
14  *  limitations under the License.\r
15  *--------------------------------------------------------------------------*/\r
16 //--------------------------------------\r
17 // XerialJ\r
18 //\r
19 // StreamAmoebaJoinTest.java\r
20 // Since: 2009/05/14 17:52:37\r
21 //\r
22 // $URL$\r
23 // $Author$\r
24 //--------------------------------------\r
25 package org.xerial.lens.relation.query;\r
26 \r
27 import static org.junit.Assert.*;\r
28 \r
29 import org.junit.After;\r
30 import org.junit.Before;\r
31 import org.junit.Test;\r
32 import org.xerial.lens.relation.DataType;\r
33 import org.xerial.lens.relation.FD;\r
34 import org.xerial.lens.relation.Node;\r
35 import org.xerial.lens.relation.query.QuerySet.QuerySetBuilder;\r
36 import org.xerial.lens.relation.schema.Schema;\r
37 import org.xerial.lens.relation.schema.SchemaBuilder;\r
38 import org.xerial.silk.SilkParser;\r
39 import org.xerial.silk.SilkParserConfig;\r
40 import org.xerial.util.FileResource;\r
41 import org.xerial.util.StopWatch;\r
42 import org.xerial.util.log.Logger;\r
43 import org.xerial.util.tree.TreeEventHandlerBase;\r
44 \r
45 public class StreamAmoebaJoinTest {\r
46     private static Logger _logger = Logger.getLogger(StreamAmoebaJoinTest.class);\r
47 \r
48     SilkParserConfig config = new SilkParserConfig();\r
49 \r
50     @Before\r
51     public void setUp() throws Exception {\r
52         config.bufferSize = 1024 * 1024 * 8; // 8MB\r
53         config.numWorkers = 2;\r
54     }\r
55 \r
56     @After\r
57     public void tearDown() throws Exception {}\r
58 \r
59     @Test\r
60     public void query() throws Exception {\r
61         QuerySetBuilder qs = new QuerySetBuilder();\r
62         qs.addQueryTarget(new SchemaBuilder().add("coordinate").add("group").add("species").add(\r
63                 "revision").add("name").add("sequence").build());\r
64         qs.addQueryTarget(new SchemaBuilder().add("coordinate").add("gene", DataType.STRUCT,\r
65                 FD.ONE_OR_MORE).build());\r
66         qs.addQueryTarget(new SchemaBuilder().add("gene").add("id").add("name").add("start").add(\r
67                 "end").add("sequence").build());\r
68 \r
69         StreamAmoebaJoin aj = new StreamAmoebaJoin(qs.build(), new AmoebaJoinHandlerBase() {\r
70 \r
71             public void newAmoeba(Schema schema, Node n1, Node n2) {\r
72                 _logger.debug(String.format("relation (%s, %s)", n1, n2));\r
73             }\r
74 \r
75             public void leaveNode(Schema schema, Node node) {\r
76                 _logger.trace(String.format("leave %s in %s", node, schema));\r
77             }\r
78 \r
79             public void text(Schema schema, Node contextNode, String nodeName, String text) {\r
80                 _logger.debug(String.format("text %s:%s of %s in %s", nodeName, text, contextNode,\r
81                         schema));\r
82             }\r
83         });\r
84 \r
85         aj.sweep(new SilkParser(FileResource.find(StreamAmoebaJoinTest.class, "sample.silk")));\r
86     }\r
87 \r
88     @Test\r
89     public void amoebaTest() throws Exception {\r
90         QuerySetBuilder qs = new QuerySetBuilder();\r
91         qs.addQueryTarget(new SchemaBuilder().add("coordinate").add("revision").build());\r
92 \r
93         StreamAmoebaJoin aj = new StreamAmoebaJoin(qs.build(), new AmoebaJoinHandlerBase() {\r
94 \r
95             int count = 0;\r
96 \r
97             public void newAmoeba(Schema schema, Node n1, Node n2) {\r
98                 _logger.debug(String.format("relation (%s, %s)", n1, n2));\r
99                 count++;\r
100             }\r
101 \r
102             public void finish() {\r
103                 assertEquals(2, count);\r
104             }\r
105 \r
106         });\r
107 \r
108         aj.sweep(new SilkParser(FileResource.find(StreamAmoebaJoinTest.class, "gene.silk")));\r
109 \r
110     }\r
111 \r
112     @Test\r
113     public void loadScaffold1() throws Exception {\r
114         QuerySet qs = new QuerySetBuilder().build();\r
115         StreamAmoebaJoin aj = new StreamAmoebaJoin(qs, new AmoebaJoinHandlerBase());\r
116         StopWatch sw = new StopWatch();\r
117         aj.sweep(new SilkParser(FileResource.find(StreamAmoebaJoinTest.class,\r
118                 "../../../silk/scaffold1.silk"), config));\r
119         _logger.info("time: " + sw.getElapsedTime());\r
120     }\r
121 \r
122     @Test\r
123     public void silkWalkPerformance() throws Exception {\r
124         SilkParser parser = new SilkParser(FileResource.find(StreamAmoebaJoinTest.class,\r
125                 "../../../silk/scaffold1.silk"), config);\r
126         StopWatch sw = new StopWatch();\r
127         parser.parse(new TreeEventHandlerBase());\r
128         _logger.info("time: " + sw.getElapsedTime());\r
129     }\r
130 \r
131 }\r