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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hadoop.pig;
import com.yahoo.vespa.hadoop.mapreduce.util.VespaConfiguration;
import com.yahoo.vespa.hadoop.mapreduce.util.VespaCounters;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hdfs.HdfsConfiguration;
import org.apache.hadoop.mapred.Counters;
import org.apache.pig.ExecType;
import org.apache.pig.PigServer;
import org.apache.pig.backend.executionengine.ExecJob;
import org.apache.pig.tools.pigstats.JobStats;
import org.apache.pig.tools.pigstats.PigStats;
import org.apache.pig.tools.pigstats.mapreduce.MRJobStats;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
public class VespaStorageTest {
@Test
public void requireThatPremadeXmlOperationsFeedSucceeds() throws Exception {
Configuration conf = new HdfsConfiguration();
conf.set(VespaConfiguration.DATA_FORMAT, "xml");
assertAllDocumentsOk("src/test/pig/feed_operations_xml.pig", conf);
}
@Test
public void requireThatPremadeOperationsFeedSucceeds() throws Exception {
assertAllDocumentsOk("src/test/pig/feed_operations.pig");
}
@Test
public void requireThatPremadeMultilineOperationsFeedSucceeds() throws Exception {
assertAllDocumentsOk("src/test/pig/feed_multiline_operations.pig");
}
@Test
public void requireThatPremadeOperationsWithJsonLoaderFeedSucceeds() throws Exception {
assertAllDocumentsOk("src/test/pig/feed_operations_with_json_loader.pig");
}
@Test
public void requireThatPremadeOperationsWithJsonLoaderFeedAndNonLegacyClientSucceeds() throws Exception {
Configuration conf = new HdfsConfiguration();
conf.set(VespaConfiguration.USE_SSL, Boolean.TRUE.toString());
conf.set(VespaConfiguration.USE_LEGACY_CLIENT, Boolean.FALSE.toString());
assertAllDocumentsOk("src/test/pig/feed_operations_with_json_loader.pig", conf);
}
@Test
public void requireThatCreateOperationsFeedSucceeds() throws Exception {
assertAllDocumentsOk("src/test/pig/feed_create_operations.pig");
}
@Test
public void requireThatCreateOperationsShortFormFeedSucceeds() throws Exception {
assertAllDocumentsOk("src/test/pig/feed_create_operations_short_form.pig");
}
@Test
public void requireThatFeedVisitDataSucceeds() throws Exception {
assertAllDocumentsOk("src/test/pig/feed_visit_data.pig");
}
private PigServer setup(String script, Configuration conf) throws Exception {
if (conf == null) {
conf = new HdfsConfiguration();
}
conf.setIfUnset(VespaConfiguration.DRYRUN, "true");
conf.setIfUnset(VespaConfiguration.ENDPOINT, "dummy-endpoint");
// Parameter substitutions - can also be set by configuration
Map<String, String> parameters = new HashMap<>();
parameters.put("ENDPOINT", "endpoint-does-not-matter-in-dryrun,another-endpoint-that-does-not-matter");
PigServer ps = new PigServer(ExecType.LOCAL, conf);
ps.setBatchOn();
ps.registerScript(script, parameters);
return ps;
}
private void assertAllDocumentsOk(String script) throws Exception {
assertAllDocumentsOk(script, null);
}
private void assertAllDocumentsOk(String script, Configuration conf) throws Exception {
PigServer ps = setup(script, conf);
List<ExecJob> jobs = ps.executeBatch();
PigStats stats = jobs.get(0).getStatistics();
for (JobStats js : stats.getJobGraph()) {
Counters hadoopCounters = ((MRJobStats)js).getHadoopCounters();
assertNotNull(hadoopCounters);
VespaCounters counters = VespaCounters.get(hadoopCounters);
assertEquals(10, counters.getDocumentsSent());
assertEquals(0, counters.getDocumentsFailed());
assertEquals(10, counters.getDocumentsOk());
}
}
}
|