Skip to content

Commit f513522

Browse files
author
Luke Bakken
committed
Add code to throw ListException for ListBuckets and timeseries ListKeys
1 parent 934a53c commit f513522

File tree

6 files changed

+109
-10
lines changed

6 files changed

+109
-10
lines changed

‎src/main/java/com/basho/riak/client/api/commands/buckets/ListBuckets.java

+24-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.basho.riak.client.api.commands.buckets;
1717

1818
import com.basho.riak.client.api.commands.ChunkedResponseIterator;
19+
import com.basho.riak.client.api.ListException;
1920
import com.basho.riak.client.api.StreamableRiakCommand;
2021
import com.basho.riak.client.core.FutureOperation;
2122
import com.basho.riak.client.core.StreamingRiakFuture;
@@ -68,10 +69,15 @@ public final class ListBuckets extends StreamableRiakCommand.StreamableRiakComma
6869
private final int timeout;
6970
private final BinaryValue type;
7071

71-
ListBuckets(Builder builder)
72+
ListBuckets(Builder builder) throws ListException
7273
{
7374
this.timeout = builder.timeout;
7475
this.type = builder.type;
76+
77+
if (builder.allowListing == false)
78+
{
79+
throw new ListException();
80+
}
7581
}
7682

7783
@Override
@@ -170,6 +176,7 @@ public static class Builder
170176
{
171177
private int timeout;
172178
private final BinaryValue type;
179+
private boolean allowListing;
173180

174181
/**
175182
* Construct a Builder for a ListBuckets command.
@@ -180,6 +187,21 @@ public Builder(String type)
180187
this.type = BinaryValue.create(type);
181188
}
182189

190+
/**
191+
* Allow this listing command
192+
* <p>
193+
* Bucket and key list operations are expensive and should not
194+
* be used in production, however using this method will allow
195+
* the command to be built.
196+
* </p>
197+
* @return a reference to this object.
198+
*/
199+
public Builder withAllowListing()
200+
{
201+
this.allowListing = true;
202+
return this;
203+
}
204+
183205
/**
184206
* Construct a Builder for a ListBuckets command.
185207
* @param type the bucket type.
@@ -208,7 +230,7 @@ public Builder withTimeout(int timeout)
208230
* Construct a new ListBuckets command.
209231
* @return a new ListBuckets command.
210232
*/
211-
public ListBuckets build()
233+
public ListBuckets build() throws ListException
212234
{
213235
return new ListBuckets(this);
214236
}

‎src/main/java/com/basho/riak/client/api/commands/timeseries/ListKeys.java

+24-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.basho.riak.client.api.commands.timeseries;
22

3+
import com.basho.riak.client.api.ListException;
34
import com.basho.riak.client.api.AsIsRiakCommand;
45
import com.basho.riak.client.core.operations.ts.ListKeysOperation;
56
import com.basho.riak.client.core.query.timeseries.QueryResult;
@@ -17,10 +18,15 @@ public class ListKeys extends AsIsRiakCommand<QueryResult, String>
1718
private final String tableName;
1819
private final int timeout;
1920

20-
private ListKeys(ListKeys.Builder builder)
21+
private ListKeys(ListKeys.Builder builder) throws ListException
2122
{
2223
this.tableName = builder.tableName;
2324
this.timeout = builder.timeout;
25+
26+
if (builder.allowListing == false)
27+
{
28+
throw new ListException();
29+
}
2430
}
2531

2632
@Override
@@ -43,6 +49,7 @@ public static class Builder
4349
{
4450
private final String tableName;
4551
private int timeout;
52+
private boolean allowListing;
4653

4754
/**
4855
* Construct a Builder for a Time Series ListKeys command.
@@ -53,6 +60,21 @@ public Builder(String tableName)
5360
this.tableName = tableName;
5461
}
5562

63+
/**
64+
* Allow this listing command
65+
* <p>
66+
* Bucket and key list operations are expensive and should not
67+
* be used in production, however using this method will allow
68+
* the command to be built.
69+
* </p>
70+
* @return a reference to this object.
71+
*/
72+
public Builder withAllowListing()
73+
{
74+
this.allowListing = true;
75+
return this;
76+
}
77+
5678
/**
5779
* Set the Riak-side timeout value.
5880
* <p>
@@ -77,7 +99,7 @@ public Builder withTimeout(int timeout)
7799
* Construct a Time Series ListKeys object.
78100
* @return a new Time Series ListKeys instance.
79101
*/
80-
public ListKeys build()
102+
public ListKeys build() throws ListException
81103
{
82104
return new ListKeys(this);
83105
}

‎src/test/java/com/basho/riak/client/api/commands/buckets/ListBucketsTest.java

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.basho.riak.client.api.commands.buckets;
22

3+
import com.basho.riak.client.api.ListException;
34
import com.basho.riak.client.api.RiakClient;
45
import com.basho.riak.client.core.*;
56
import com.basho.riak.client.core.operations.ListBucketsOperation;
@@ -56,7 +57,7 @@ public void init() throws Exception
5657
private void testListBuckets(String bucketType) throws Exception
5758
{
5859
final BinaryValue type = BinaryValue.createFromUtf8(bucketType);
59-
ListBuckets.Builder list = new ListBuckets.Builder(type);
60+
ListBuckets.Builder list = new ListBuckets.Builder(type).withAllowListing();
6061
client.execute(list.build());
6162

6263
ArgumentCaptor<FutureOperation> captor =
@@ -70,6 +71,24 @@ private void testListBuckets(String bucketType) throws Exception
7071
Assert.assertEquals(ByteString.copyFrom(type.unsafeGetValue()), builder.getType());
7172
}
7273

74+
@Test
75+
public void listBucketsThrowsListException()
76+
{
77+
boolean sawException = false;
78+
79+
ListBuckets.Builder b = new ListBuckets.Builder("bucket_type");
80+
try
81+
{
82+
b.build();
83+
}
84+
catch (ListException ex)
85+
{
86+
sawException = true;
87+
}
88+
89+
Assert.assertTrue(sawException);
90+
}
91+
7392
@Test
7493
public void bucketTypeBuiltCorrectly() throws Exception
7594
{

‎src/test/java/com/basho/riak/client/api/commands/buckets/itest/ITestListBuckets.java

+20-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.basho.riak.client.api.commands.buckets.itest;
1818

19+
import com.basho.riak.client.api.ListException;
1920
import com.basho.riak.client.api.RiakClient;
2021
import com.basho.riak.client.api.commands.buckets.ListBuckets;
2122
import com.basho.riak.client.api.commands.kv.StoreValue;
@@ -35,6 +36,7 @@
3536
import static org.junit.Assert.assertEquals;
3637
import static org.junit.Assert.assertFalse;
3738
import static org.junit.Assert.assertTrue;
39+
import static org.junit.Assert.fail;
3840
import static org.junit.Assume.assumeTrue;
3941

4042
/**
@@ -91,7 +93,15 @@ public void testListBucketsStreamingTestType() throws InterruptedException, Exec
9193

9294
private void testListBuckets(Namespace namespace) throws InterruptedException, ExecutionException
9395
{
94-
ListBuckets listBucketsCommand = new ListBuckets.Builder(namespace.getBucketType()).build();
96+
ListBuckets listBucketsCommand = null;
97+
try
98+
{
99+
listBucketsCommand = new ListBuckets.Builder(namespace.getBucketType()).withAllowListing().build();
100+
}
101+
catch (ListException ex)
102+
{
103+
fail(ex.getMessage());
104+
}
95105

96106
final ListBuckets.Response listResponse = client.execute(listBucketsCommand);
97107

@@ -109,7 +119,15 @@ private void testListBuckets(Namespace namespace) throws InterruptedException, E
109119

110120
private void testListBucketsStreaming(Namespace namespace) throws InterruptedException, ExecutionException
111121
{
112-
ListBuckets listBucketsCommand = new ListBuckets.Builder(namespace.getBucketType()).build();
122+
ListBuckets listBucketsCommand = null;
123+
try
124+
{
125+
listBucketsCommand = new ListBuckets.Builder(namespace.getBucketType()).withAllowListing().build();
126+
}
127+
catch (ListException ex)
128+
{
129+
fail(ex.getMessage());
130+
}
113131

114132
final RiakFuture<ListBuckets.Response, BinaryValue> streamingFuture =
115133
client.executeAsyncStreaming(listBucketsCommand, 500);

‎src/test/java/com/basho/riak/client/api/commands/buckets/itest/ITestListKeys.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
import static org.junit.Assert.assertEquals;
3737
import static org.junit.Assert.assertTrue;
38+
import static org.junit.Assert.fail;
3839
import static org.junit.Assume.assumeTrue;
3940

4041
/**
@@ -66,11 +67,19 @@ public static void cleanup() throws ExecutionException, InterruptedException
6667
}
6768

6869
@Test
69-
public void testLargeStreamingListKeys() throws ListException, ExecutionException, InterruptedException
70+
public void testLargeStreamingListKeys() throws ExecutionException, InterruptedException
7071
{
7172
assumeTrue(testBucketType);
7273

73-
ListKeys lk = new ListKeys.Builder(typedNamespace).withAllowListing().build();
74+
ListKeys lk = null;
75+
try
76+
{
77+
lk = new ListKeys.Builder(typedNamespace).withAllowListing().build();
78+
}
79+
catch (ListException ex)
80+
{
81+
fail(ex.getMessage());
82+
}
7483

7584
final RiakFuture<ListKeys.Response, Namespace> streamFuture =
7685
client.executeAsyncStreaming(lk, 200);

‎src/test/java/com/basho/riak/client/api/commands/itest/ITestTimeSeries.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.basho.riak.client.api.commands.itest;
22

3+
import com.basho.riak.client.api.ListException;
34
import com.basho.riak.client.api.RiakClient;
45
import com.basho.riak.client.api.commands.buckets.FetchBucketProperties;
56
import com.basho.riak.client.api.commands.buckets.StoreBucketProperties;
@@ -121,7 +122,15 @@ public void test_d_TestListingKeysReturnsThem() throws ExecutionException, Inter
121122
{
122123
RiakClient client = new RiakClient(cluster);
123124

124-
ListKeys listKeys = new ListKeys.Builder(tableName).build();
125+
ListKeys listKeys = null;
126+
try
127+
{
128+
listKeys = new ListKeys.Builder(tableName).withAllowListing().build();
129+
}
130+
catch (ListException ex)
131+
{
132+
fail(ex.getMessage());
133+
}
125134

126135
final RiakFuture<QueryResult, String> listKeysFuture = client.executeAsync(listKeys);
127136

0 commit comments

Comments
 (0)