vayacondios-server 0.1.7 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +6 -2
- data/examples/java/ItemSetTest.java +76 -0
- data/lib/vayacondios/client/itemset.rb +37 -1
- data/lib/vayacondios/version.rb +1 -1
- data/pom.xml +14 -1
- data/src/main/java/ItemSetTest.java +76 -0
- data/src/main/java/com/infochimps/util/HttpHelper.java +20 -11
- data/src/main/java/com/infochimps/vayacondios/ItemSets.java +34 -34
- data/src/main/java/com/infochimps/vayacondios/VCDIntegrationTest.java +48 -19
- metadata +6 -4
data/README.md
CHANGED
@@ -1,7 +1,11 @@
|
|
1
|
-
# WARNING! THIS DOCUMENT IS OUTDATED AND MAY NOT REFLECT ACTUAL CODE! GO READ THE SPECS FOR BEHAVIORS!
|
2
|
-
|
3
1
|
# Vaya con Dios
|
4
2
|
|
3
|
+
## Warning
|
4
|
+
|
5
|
+
Some of the documentation on this page is for legacy versions of
|
6
|
+
Vayacondios. Until this document is updated, please see the specs for
|
7
|
+
the Ruby code or compile the javadocs for the Java API.
|
8
|
+
|
5
9
|
> "Data goes in. The right thing happens."
|
6
10
|
|
7
11
|
Simple enough to use in a shell script, performant enough to use everywhere.
|
@@ -0,0 +1,76 @@
|
|
1
|
+
import com.infochimps.vayacondios.Organization;
|
2
|
+
import com.infochimps.vayacondios.VayacondiosClient;
|
3
|
+
import com.infochimps.vayacondios.ItemSets;
|
4
|
+
import static com.infochimps.vayacondios.ItemSets.Item;
|
5
|
+
import static com.infochimps.vayacondios.ItemSets.ItemSet;
|
6
|
+
|
7
|
+
import java.io.*;
|
8
|
+
import java.util.*;
|
9
|
+
|
10
|
+
public class ItemSetTest {
|
11
|
+
private static final int VCD_PORT = 8000;
|
12
|
+
|
13
|
+
public static void main(String argv[]) throws IOException {
|
14
|
+
// Instantiate a new Vayacondios client.
|
15
|
+
VayacondiosClient client = new VayacondiosClient("localhost", VCD_PORT);
|
16
|
+
|
17
|
+
// Organizations can allow for testing and multiple environments
|
18
|
+
// (staging, development).
|
19
|
+
Organization org = client.organization("test");
|
20
|
+
|
21
|
+
// At the moment, only the itemsets protocol is supported via a
|
22
|
+
// Java API.
|
23
|
+
ItemSets isets = org.itemsets();
|
24
|
+
|
25
|
+
List<Item> foobar = Arrays.asList(new Item("foo"), new Item("bar"));
|
26
|
+
|
27
|
+
// All of the following are equivalent ways to clobber the itemset
|
28
|
+
// at topic my_topic and id my_id, replacing it with the items
|
29
|
+
// "foo" and "bar." The first and second exist to avoid
|
30
|
+
// instantiating new objects repeatedly when a code path must
|
31
|
+
// access many different topics and ids.
|
32
|
+
isets .create("my_topic", "my_id", foobar);
|
33
|
+
isets.topic("my_topic") .create( "my_id", foobar);
|
34
|
+
isets.topic("my_topic").itemSet("my_id").create( foobar);
|
35
|
+
|
36
|
+
List<Item> fetched;
|
37
|
+
|
38
|
+
// Similarly, these are all equivalent ways to fetch items.
|
39
|
+
fetched = isets .fetch("my_topic", "my_id");
|
40
|
+
fetched = isets.topic("my_topic") .fetch( "my_id");
|
41
|
+
fetched = isets.topic("my_topic").itemSet("my_id").fetch( );
|
42
|
+
|
43
|
+
ItemSet iset = isets.topic("my_topic").itemSet("my_id");
|
44
|
+
|
45
|
+
// foo and bar will be printed, along with their types: STRING
|
46
|
+
System.out.println("fetched items: " + fetched);
|
47
|
+
|
48
|
+
List<Item> bazqux = Arrays.asList(new Item("baz"), new Item("qux"));
|
49
|
+
|
50
|
+
// Updating an itemset with a list of items ensures the presence
|
51
|
+
// in the itemset of all of the items in the specified list.
|
52
|
+
isets .update("my_topic", "my_id", bazqux);
|
53
|
+
isets.topic("my_topic") .update( "my_id", bazqux);
|
54
|
+
isets.topic("my_topic").itemSet("my_id").update( bazqux);
|
55
|
+
|
56
|
+
// foo, bar, baz, and qux will all be printed.
|
57
|
+
System.out.println("after update: " + iset.fetch());
|
58
|
+
|
59
|
+
List<Item> barbaz = Arrays.asList(new Item("bar"), new Item("baz"));
|
60
|
+
|
61
|
+
// Updating an itemset with a list of items ensures the presence
|
62
|
+
// in the itemset of all of the items in the specified list.
|
63
|
+
isets .remove("my_topic", "my_id", barbaz);
|
64
|
+
isets.topic("my_topic") .remove( "my_id", barbaz);
|
65
|
+
isets.topic("my_topic").itemSet("my_id").remove( barbaz);
|
66
|
+
|
67
|
+
// foo and qux will now be printed
|
68
|
+
System.out.println("after removing: " + iset.fetch());
|
69
|
+
|
70
|
+
// Create an empty itemset to effectively delete it.
|
71
|
+
iset.create(Collections.EMPTY_LIST);
|
72
|
+
|
73
|
+
// foo and qux will now be printed
|
74
|
+
System.out.println("after deletion: " + iset.fetch());
|
75
|
+
}
|
76
|
+
}
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'gorillib/logger/log'
|
1
2
|
require 'net/http'
|
2
3
|
require 'multi_json'
|
3
4
|
|
@@ -29,7 +30,6 @@ class Vayacondios
|
|
29
30
|
execute_request(_req(:remove, ary, organization, topic, id))
|
30
31
|
end
|
31
32
|
|
32
|
-
|
33
33
|
private
|
34
34
|
|
35
35
|
def execute_request req
|
@@ -68,5 +68,41 @@ class Vayacondios
|
|
68
68
|
end
|
69
69
|
end
|
70
70
|
end
|
71
|
+
|
72
|
+
# Subclasses should implement the remove_items(arr) and
|
73
|
+
# add_items(arr) methods, both of which will be called with arrays
|
74
|
+
# when the items in an itemset change. The run method polls the
|
75
|
+
# provided itemset at a specified interval and calls these methods
|
76
|
+
# appropriately.
|
77
|
+
class ItemSetListener
|
78
|
+
POLL_WAIT_SEC=2
|
79
|
+
|
80
|
+
def initialize itemset, poll_wait_sec = POLL_WAIT_SEC
|
81
|
+
@itemset = itemset
|
82
|
+
@items = []
|
83
|
+
@poll_wait_sec = poll_wait_sec
|
84
|
+
end
|
85
|
+
|
86
|
+
def setup() end
|
87
|
+
def teardown() end
|
88
|
+
|
89
|
+
def run
|
90
|
+
setup
|
91
|
+
loop do
|
92
|
+
new_items = @itemset.fetch || []
|
93
|
+
|
94
|
+
Log.debug "currently configured: #{@items.inspect}"
|
95
|
+
Log.debug "new items: #{new_items.inspect}"
|
96
|
+
|
97
|
+
add_items(new_items - @items)
|
98
|
+
remove_items(@items - new_items)
|
99
|
+
|
100
|
+
@items = new_items
|
101
|
+
|
102
|
+
sleep @poll_wait_sec
|
103
|
+
end
|
104
|
+
teardown
|
105
|
+
end
|
106
|
+
end
|
71
107
|
end
|
72
108
|
end
|
data/lib/vayacondios/version.rb
CHANGED
data/pom.xml
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
<groupId>com.infochimps</groupId>
|
5
5
|
<artifactId>vayacondios</artifactId>
|
6
6
|
<packaging>jar</packaging>
|
7
|
-
<version>1.0.
|
7
|
+
<version>1.0.1-SNAPSHOT</version>
|
8
8
|
<name>java-common</name>
|
9
9
|
<url>http://maven.apache.org</url>
|
10
10
|
|
@@ -14,6 +14,19 @@
|
|
14
14
|
<version>1.0.0-SNAPSHOT</version>
|
15
15
|
</parent>
|
16
16
|
|
17
|
+
<reporting>
|
18
|
+
<plugins>
|
19
|
+
<plugin>
|
20
|
+
<groupId>org.apache.maven.plugins</groupId>
|
21
|
+
<artifactId>maven-javadoc-plugin</artifactId>
|
22
|
+
<version>2.9</version>
|
23
|
+
<configuration>
|
24
|
+
<show>public</show>
|
25
|
+
</configuration>
|
26
|
+
</plugin>
|
27
|
+
</plugins>
|
28
|
+
</reporting>
|
29
|
+
|
17
30
|
<build>
|
18
31
|
<plugins>
|
19
32
|
<plugin>
|
@@ -0,0 +1,76 @@
|
|
1
|
+
import com.infochimps.vayacondios.Organization;
|
2
|
+
import com.infochimps.vayacondios.VayacondiosClient;
|
3
|
+
import com.infochimps.vayacondios.ItemSets;
|
4
|
+
import static com.infochimps.vayacondios.ItemSets.Item;
|
5
|
+
import static com.infochimps.vayacondios.ItemSets.ItemSet;
|
6
|
+
|
7
|
+
import java.io.*;
|
8
|
+
import java.util.*;
|
9
|
+
|
10
|
+
public class ItemSetTest {
|
11
|
+
private static final int VCD_PORT = 8000;
|
12
|
+
|
13
|
+
public static void main(String argv[]) throws IOException {
|
14
|
+
// Instantiate a new Vayacondios client.
|
15
|
+
VayacondiosClient client = new VayacondiosClient("localhost", VCD_PORT);
|
16
|
+
|
17
|
+
// Organizations can allow for testing and multiple environments
|
18
|
+
// (staging, development).
|
19
|
+
Organization org = client.organization("test");
|
20
|
+
|
21
|
+
// At the moment, only the itemsets protocol is supported via a
|
22
|
+
// Java API.
|
23
|
+
ItemSets isets = org.itemsets();
|
24
|
+
|
25
|
+
List<Item> foobar = Arrays.asList(new Item("foo"), new Item("bar"));
|
26
|
+
|
27
|
+
// All of the following are equivalent ways to clobber the itemset
|
28
|
+
// at topic my_topic and id my_id, replacing it with the items
|
29
|
+
// "foo" and "bar." The first and second exist to avoid
|
30
|
+
// instantiating new objects repeatedly when a code path must
|
31
|
+
// access many different topics and ids.
|
32
|
+
isets .create("my_topic", "my_id", foobar);
|
33
|
+
isets.topic("my_topic") .create( "my_id", foobar);
|
34
|
+
isets.topic("my_topic").itemSet("my_id").create( foobar);
|
35
|
+
|
36
|
+
List<Item> fetched;
|
37
|
+
|
38
|
+
// Similarly, these are all equivalent ways to fetch items.
|
39
|
+
fetched = isets .fetch("my_topic", "my_id");
|
40
|
+
fetched = isets.topic("my_topic") .fetch( "my_id");
|
41
|
+
fetched = isets.topic("my_topic").itemSet("my_id").fetch( );
|
42
|
+
|
43
|
+
ItemSet iset = isets.topic("my_topic").itemSet("my_id");
|
44
|
+
|
45
|
+
// foo and bar will be printed, along with their types: STRING
|
46
|
+
System.out.println("fetched items: " + fetched);
|
47
|
+
|
48
|
+
List<Item> bazqux = Arrays.asList(new Item("baz"), new Item("qux"));
|
49
|
+
|
50
|
+
// Updating an itemset with a list of items ensures the presence
|
51
|
+
// in the itemset of all of the items in the specified list.
|
52
|
+
isets .update("my_topic", "my_id", bazqux);
|
53
|
+
isets.topic("my_topic") .update( "my_id", bazqux);
|
54
|
+
isets.topic("my_topic").itemSet("my_id").update( bazqux);
|
55
|
+
|
56
|
+
// foo, bar, baz, and qux will all be printed.
|
57
|
+
System.out.println("after update: " + iset.fetch());
|
58
|
+
|
59
|
+
List<Item> barbaz = Arrays.asList(new Item("bar"), new Item("baz"));
|
60
|
+
|
61
|
+
// Updating an itemset with a list of items ensures the presence
|
62
|
+
// in the itemset of all of the items in the specified list.
|
63
|
+
isets .remove("my_topic", "my_id", barbaz);
|
64
|
+
isets.topic("my_topic") .remove( "my_id", barbaz);
|
65
|
+
isets.topic("my_topic").itemSet("my_id").remove( barbaz);
|
66
|
+
|
67
|
+
// foo and qux will now be printed
|
68
|
+
System.out.println("after removing: " + iset.fetch());
|
69
|
+
|
70
|
+
// Create an empty itemset to effectively delete it.
|
71
|
+
iset.create(Collections.EMPTY_LIST);
|
72
|
+
|
73
|
+
// foo and qux will now be printed
|
74
|
+
System.out.println("after deletion: " + iset.fetch());
|
75
|
+
}
|
76
|
+
}
|
@@ -35,19 +35,30 @@ public class HttpHelper {
|
|
35
35
|
public static BufferedReader open(Logger log,
|
36
36
|
String urlString,
|
37
37
|
Charset inputCharset) throws IOException {
|
38
|
-
|
39
|
-
return getReader(con, log, inputCharset);
|
38
|
+
return getReader(openStream(log, urlString), inputCharset);
|
40
39
|
}
|
41
40
|
|
42
41
|
public static BufferedReader open(Logger log,
|
43
42
|
String urlString,
|
44
43
|
HashMap<String,String> extraHeaders,
|
45
44
|
Charset inputCharset) throws IOException {
|
45
|
+
return getReader(openStream(log, urlString, extraHeaders), inputCharset);
|
46
|
+
|
47
|
+
}
|
48
|
+
|
49
|
+
public static InputStream openStream(Logger log,
|
50
|
+
String urlString) throws IOException {
|
51
|
+
HttpURLConnection con = getConnection(urlString, log);
|
52
|
+
return getStream(con, log);
|
53
|
+
}
|
46
54
|
|
55
|
+
public static InputStream openStream(Logger log,
|
56
|
+
String urlString,
|
57
|
+
HashMap<String,String> extraHeaders) throws IOException {
|
47
58
|
HttpURLConnection con = getConnection(urlString, log);
|
48
59
|
for (Entry<String,String> header : extraHeaders.entrySet())
|
49
60
|
con.setRequestProperty(header.getKey(), header.getValue());
|
50
|
-
return
|
61
|
+
return getStream(con, log);
|
51
62
|
}
|
52
63
|
|
53
64
|
private static HttpURLConnection getConnection(String urlString, Logger log) throws IOException {
|
@@ -71,9 +82,8 @@ public class HttpHelper {
|
|
71
82
|
return con;
|
72
83
|
}
|
73
84
|
|
74
|
-
private static
|
75
|
-
|
76
|
-
Charset inputCharset) throws IOException {
|
85
|
+
private static InputStream getStream(HttpURLConnection con,
|
86
|
+
Logger log) throws IOException {
|
77
87
|
InputStream in = null;
|
78
88
|
|
79
89
|
try { in = con.getInputStream(); }
|
@@ -95,18 +105,17 @@ public class HttpHelper {
|
|
95
105
|
throw e;
|
96
106
|
}
|
97
107
|
|
108
|
+
log.debug("successfully opened connection to " + con.getURL().toString());
|
98
109
|
String encoding = con.getContentEncoding();
|
99
110
|
log.debug("Got HTTP stream with content encoding type '" + encoding + "'");
|
100
111
|
|
101
|
-
|
112
|
+
return (encoding != null && encoding.equals("gzip")) ? new GZIPInputStream(in) : in;
|
113
|
+
}
|
102
114
|
|
115
|
+
private static BufferedReader getReader(InputStream in, Charset inputCharset) {
|
103
116
|
InputStreamReader istream_reader = new InputStreamReader(in, inputCharset);
|
104
117
|
BufferedReader reader = new BufferedReader(istream_reader);
|
105
118
|
|
106
|
-
log.debug("successfully opened connection to {} with character encoding {}",
|
107
|
-
con.getURL().toString(),
|
108
|
-
istream_reader.getEncoding());
|
109
|
-
|
110
119
|
return reader;
|
111
120
|
}
|
112
121
|
}
|
@@ -113,50 +113,50 @@ public class ItemSets extends Organization {
|
|
113
113
|
* Creates a new itemset with the specified topic and id, clobbering
|
114
114
|
* any existing itemset with the same topic and id.
|
115
115
|
*
|
116
|
-
* @param items items whose existence should be ensured in the set.
|
117
116
|
* @param topic A Vayacondios topic has many ids. See vayacondios
|
118
117
|
* documentation for further details.
|
119
118
|
* @param id A Vayacondios id, together with the server,
|
120
119
|
* organization, and topic, specifies a unique
|
121
120
|
* itemset.
|
121
|
+
* @param items items whose existence should be ensured in the set.
|
122
122
|
*/
|
123
|
-
public void create(
|
124
|
-
String
|
125
|
-
|
126
|
-
mutate("PUT",
|
123
|
+
public void create(String topic,
|
124
|
+
String id,
|
125
|
+
List<Item> items) throws IOException {
|
126
|
+
mutate("PUT", topic, id, items);
|
127
127
|
}
|
128
128
|
|
129
129
|
/**
|
130
130
|
* Ensures the absence of the specified items from the specified itemset.q
|
131
131
|
*
|
132
|
-
* @param items items whose absence should be ensured in the set.
|
133
132
|
* @param topic A Vayacondios topic has many ids. See vayacondios
|
134
133
|
* documentation for further details.
|
135
134
|
* @param id A Vayacondios id, together with the server,
|
136
135
|
* organization, and topic, specifies a unique
|
137
136
|
* itemset.
|
137
|
+
* @param items items whose absence should be ensured in the set.
|
138
138
|
*/
|
139
|
-
public void remove(
|
140
|
-
String
|
141
|
-
|
142
|
-
mutate("DELETE",
|
139
|
+
public void remove(String topic,
|
140
|
+
String id,
|
141
|
+
List<Item> items) throws IOException {
|
142
|
+
mutate("DELETE", topic, id, items);
|
143
143
|
}
|
144
144
|
|
145
145
|
/**
|
146
146
|
* Updates the current value of an itemset, ensuring the existence
|
147
147
|
* of the specified items.
|
148
148
|
*
|
149
|
-
* @param items items whose existence should be ensured in the set.
|
150
149
|
* @param topic A Vayacondios topic has many ids. See vayacondios
|
151
150
|
* documentation for further details.
|
152
151
|
* @param id A Vayacondios id, together with the server,
|
153
152
|
* organization, and topic, specifies a unique
|
154
153
|
* itemset.
|
154
|
+
* @param items items whose existence should be ensured in the set.
|
155
155
|
*/
|
156
|
-
public void update(
|
157
|
-
String
|
158
|
-
|
159
|
-
mutate("PATCH",
|
156
|
+
public void update(String topic,
|
157
|
+
String id,
|
158
|
+
List<Item> items) throws IOException {
|
159
|
+
mutate("PATCH", topic, id, items);
|
160
160
|
}
|
161
161
|
|
162
162
|
//----------------------------------------------------------------------------
|
@@ -170,9 +170,9 @@ public class ItemSets extends Organization {
|
|
170
170
|
//----------------------------------------------------------------------------
|
171
171
|
|
172
172
|
protected void mutate(String method,
|
173
|
-
List<Item> items,
|
174
173
|
String topic,
|
175
|
-
String id
|
174
|
+
String id,
|
175
|
+
List<Item> items) throws IOException {
|
176
176
|
|
177
177
|
// serialize the items
|
178
178
|
HashMap content = new HashMap();
|
@@ -273,7 +273,7 @@ public class ItemSets extends Organization {
|
|
273
273
|
//--------------------------------------------------------------------------
|
274
274
|
|
275
275
|
/**
|
276
|
-
* @see ItemSets
|
276
|
+
* @see ItemSets#fetch
|
277
277
|
*/
|
278
278
|
public List<Item> fetch(String id) throws IOException {
|
279
279
|
return fetch(getTopic(), id);
|
@@ -282,22 +282,22 @@ public class ItemSets extends Organization {
|
|
282
282
|
/**
|
283
283
|
* @see ItemSets::create
|
284
284
|
*/
|
285
|
-
public void create(List<Item> items
|
286
|
-
create(
|
285
|
+
public void create(String id, List<Item> items) throws IOException {
|
286
|
+
create(getTopic(), id, items);
|
287
287
|
}
|
288
288
|
|
289
289
|
/**
|
290
|
-
* @see ItemSets
|
290
|
+
* @see ItemSets#remove
|
291
291
|
*/
|
292
|
-
public void remove(List<Item> items
|
293
|
-
remove(
|
292
|
+
public void remove(String id, List<Item> items) throws IOException {
|
293
|
+
remove(getTopic(), id, items);
|
294
294
|
}
|
295
295
|
|
296
296
|
/**
|
297
|
-
* @see ItemSets
|
297
|
+
* @see ItemSets#update
|
298
298
|
*/
|
299
|
-
public void update(List<Item> items
|
300
|
-
update(
|
299
|
+
public void update(String id, List<Item> items) throws IOException {
|
300
|
+
update(getTopic(), id, items);
|
301
301
|
}
|
302
302
|
|
303
303
|
//--------------------------------------------------------------------------
|
@@ -336,31 +336,31 @@ public class ItemSets extends Organization {
|
|
336
336
|
//--------------------------------------------------------------------------
|
337
337
|
|
338
338
|
/**
|
339
|
-
* @see ItemSets
|
339
|
+
* @see ItemSets#fetch
|
340
340
|
*/
|
341
341
|
public List<Item> fetch() throws IOException {
|
342
342
|
return fetch(getId());
|
343
343
|
}
|
344
344
|
|
345
345
|
/**
|
346
|
-
* @see ItemSets
|
346
|
+
* @see ItemSets#create
|
347
347
|
*/
|
348
348
|
public void create(List<Item> items) throws IOException {
|
349
|
-
create(
|
349
|
+
create(getId(), items);
|
350
350
|
}
|
351
351
|
|
352
352
|
/**
|
353
|
-
* @see ItemSets
|
353
|
+
* @see ItemSets#remove
|
354
354
|
*/
|
355
355
|
public void remove(List<Item> items) throws IOException {
|
356
|
-
remove(
|
356
|
+
remove(getId(), items);
|
357
357
|
}
|
358
358
|
|
359
359
|
/**
|
360
|
-
* @see ItemSets
|
360
|
+
* @see ItemSets#update
|
361
361
|
*/
|
362
362
|
public void update(List<Item> items) throws IOException {
|
363
|
-
update(
|
363
|
+
update(getId(), items);
|
364
364
|
}
|
365
365
|
|
366
366
|
//--------------------------------------------------------------------------
|
@@ -460,4 +460,4 @@ public class ItemSets extends Organization {
|
|
460
460
|
private TYPE _type;
|
461
461
|
private enum TYPE {BOOLEAN, NUMBER, STRING}
|
462
462
|
}
|
463
|
-
}
|
463
|
+
}
|
@@ -6,6 +6,7 @@ import static com.infochimps.util.CurrentClass.getLogger;
|
|
6
6
|
|
7
7
|
import static com.infochimps.vayacondios.ItemSets.Item;
|
8
8
|
import static com.infochimps.vayacondios.ItemSets.ItemSet;
|
9
|
+
import com.infochimps.vayacondios.ItemSets;
|
9
10
|
|
10
11
|
import java.io.IOException;
|
11
12
|
import java.util.Arrays;
|
@@ -19,32 +20,58 @@ public class VCDIntegrationTest {
|
|
19
20
|
private static final int VCD_PORT = 8000;
|
20
21
|
private static final Logger LOG = getLogger();
|
21
22
|
|
22
|
-
private static
|
23
|
+
private static ItemSets itemSets() {
|
23
24
|
return new VayacondiosClient("localhost", VCD_PORT).
|
24
25
|
organization("org").
|
25
|
-
itemsets()
|
26
|
-
topic("topic").
|
27
|
-
itemSet("id");
|
26
|
+
itemsets();
|
28
27
|
}
|
29
28
|
|
30
|
-
private static
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
29
|
+
private static List<Item> buildItemList(String items[]) {
|
30
|
+
List<Item> result = new ArrayList<Item>();
|
31
|
+
for (String s : items) result.add(new Item(s));
|
32
|
+
return result;
|
33
|
+
}
|
35
34
|
|
36
|
-
|
35
|
+
private static List<String> getStrings(List<Item> items) {
|
36
|
+
List<String> result = new ArrayList<String>();
|
37
|
+
for (Item i : items) result.add(i.getAsString());
|
38
|
+
return result;
|
39
|
+
}
|
40
|
+
|
41
|
+
private static List<String> fetch() throws IOException {
|
42
|
+
return getStrings(itemSets().fetch("topic", "id"));
|
43
|
+
}
|
44
|
+
|
45
|
+
private static void create(String... items) throws IOException {
|
46
|
+
itemSets().create("topic", "id", buildItemList(items));
|
47
|
+
}
|
48
|
+
|
49
|
+
private static void remove(String... items) throws IOException {
|
50
|
+
itemSets().remove("topic", "id", buildItemList(items));
|
51
|
+
}
|
37
52
|
|
38
|
-
|
39
|
-
|
53
|
+
private static void update(String... items) throws IOException {
|
54
|
+
itemSets().update("topic", "id", buildItemList(items));
|
55
|
+
}
|
56
|
+
|
57
|
+
private static void assertEquals(String... expectedArr)
|
58
|
+
throws IOException {
|
59
|
+
List<String> items = fetch();
|
60
|
+
List<String> copy = new ArrayList<String>();
|
61
|
+
List<String> expected = Arrays.asList(expectedArr);
|
62
|
+
|
63
|
+
if (!items.containsAll(expected)) {
|
64
|
+
copy = new ArrayList(); copy.addAll(expected);
|
40
65
|
LOG.trace("removing items. copy change? " + copy.removeAll(items));
|
41
66
|
System.out.println("\033[31mFAIL\033[0m: expected but absent: " + copy);
|
42
|
-
}
|
43
|
-
|
67
|
+
} else
|
68
|
+
System.out.println("\033[32mSUCCESS\033[0m: all expected items present");
|
69
|
+
if (!expected.containsAll(items)) {
|
44
70
|
copy = new ArrayList(); copy.addAll(items);
|
45
|
-
LOG.trace("removing items. copy change? " + copy.removeAll(
|
71
|
+
LOG.trace("removing items. copy change? " + copy.removeAll(expected));
|
46
72
|
System.out.println("\033[31mFAIL\033[0m: unexpected and present: " + copy);
|
47
|
-
}
|
73
|
+
} else
|
74
|
+
System.out.println("\033[32mSUCCESS\033[0m: no unexpected items present");
|
48
75
|
}
|
49
76
|
|
50
77
|
public static void main(String argv[]) {
|
@@ -53,11 +80,13 @@ public class VCDIntegrationTest {
|
|
53
80
|
System.out.println("Running Vayacondios integration test...");
|
54
81
|
|
55
82
|
try {
|
56
|
-
|
83
|
+
create("foo", "baz", "bar", "bing");
|
57
84
|
assertEquals("foo", "baz", "bar", "bing");
|
58
|
-
|
85
|
+
|
86
|
+
update("biff");
|
59
87
|
assertEquals("foo", "baz", "bar", "bing", "biff");
|
60
|
-
|
88
|
+
|
89
|
+
remove("biff", "bar");
|
61
90
|
assertEquals("foo", "baz", "bing");
|
62
91
|
|
63
92
|
System.out.println("Integration test complete.");
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vayacondios-server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.10
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2013-
|
15
|
+
date: 2013-04-02 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: configliere
|
@@ -197,6 +197,7 @@ files:
|
|
197
197
|
- config/http_shim.rb
|
198
198
|
- config/vayacondios.example.yaml
|
199
199
|
- config/vayacondios.yaml
|
200
|
+
- examples/java/ItemSetTest.java
|
200
201
|
- lib/tasks/publish.rake
|
201
202
|
- lib/tasks/spec.rake
|
202
203
|
- lib/tasks/yard.rake
|
@@ -243,6 +244,7 @@ files:
|
|
243
244
|
- spec/server/server_spec.rb
|
244
245
|
- spec/spec_helper.rb
|
245
246
|
- spec/support/mongo_cleaner.rb
|
247
|
+
- src/main/java/ItemSetTest.java
|
246
248
|
- src/main/java/com/infochimps/util/CurrentClass.java
|
247
249
|
- src/main/java/com/infochimps/util/DebugUtil.java
|
248
250
|
- src/main/java/com/infochimps/util/HttpHelper.java
|
@@ -267,7 +269,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
267
269
|
version: '0'
|
268
270
|
segments:
|
269
271
|
- 0
|
270
|
-
hash:
|
272
|
+
hash: 1185484650458955760
|
271
273
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
272
274
|
none: false
|
273
275
|
requirements:
|
@@ -276,7 +278,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
276
278
|
version: '0'
|
277
279
|
segments:
|
278
280
|
- 0
|
279
|
-
hash:
|
281
|
+
hash: 1185484650458955760
|
280
282
|
requirements: []
|
281
283
|
rubyforge_project:
|
282
284
|
rubygems_version: 1.8.25
|