Repository: incubator-blur Updated Branches: refs/heads/master 528ef3ff7 -> 3ae19454f
Starting to add unit tests for the new command implementation. Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/3ae19454 Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/3ae19454 Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/3ae19454 Branch: refs/heads/master Commit: 3ae19454f8fbee7f46c24b899be6ed23bc341f8a Parents: 528ef3f Author: Aaron McCurry <[email protected]> Authored: Wed Sep 10 10:49:38 2014 -0400 Committer: Aaron McCurry <[email protected]> Committed: Wed Sep 10 10:49:38 2014 -0400 ---------------------------------------------------------------------- .../org/apache/blur/command/WaitForSeconds.java | 43 ---- .../apache/blur/command/BaseCommandManager.java | 8 +- .../org/apache/blur/command/ExecutionId.java | 5 + .../java/org/apache/blur/command/Response.java | 7 + .../blur/command/ShardCommandManager.java | 15 +- .../apache/blur/command/TimeoutException.java | 6 +- .../apache/blur/server/BlurServerContext.java | 12 +- .../blur/thrift/BlurControllerServer.java | 13 +- .../org/apache/blur/thrift/BlurShardServer.java | 7 +- .../org/apache/blur/command/BlurArrayTest.java | 61 +++++ .../blur/command/ShardCommandManagerTest.java | 258 +++++++++++++++++++ .../org/apache/blur/command/WaitForSeconds.java | 46 ++++ .../blur/manager/command/BlurArrayTest.java | 61 ----- .../services/org.apache.blur.command.Commands | 16 ++ 14 files changed, 435 insertions(+), 123 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/3ae19454/blur-command/src/main/java/org/apache/blur/command/WaitForSeconds.java ---------------------------------------------------------------------- diff --git a/blur-command/src/main/java/org/apache/blur/command/WaitForSeconds.java b/blur-command/src/main/java/org/apache/blur/command/WaitForSeconds.java deleted file mode 100644 index 833384b..0000000 --- a/blur-command/src/main/java/org/apache/blur/command/WaitForSeconds.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.blur.command; - -import java.io.IOException; - -import org.apache.blur.command.Command; -import org.apache.blur.command.IndexContext; -import org.apache.blur.command.IndexReadCommand; - -@SuppressWarnings("serial") -public class WaitForSeconds extends Command implements IndexReadCommand<Boolean> { - - @Override - public Boolean execute(IndexContext context) throws IOException { - try { - Thread.sleep(30000); - } catch (InterruptedException e) { - throw new IOException(e); - } - return true; - } - - @Override - public String getName() { - return "wait"; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/3ae19454/blur-core/src/main/java/org/apache/blur/command/BaseCommandManager.java ---------------------------------------------------------------------- diff --git a/blur-core/src/main/java/org/apache/blur/command/BaseCommandManager.java b/blur-core/src/main/java/org/apache/blur/command/BaseCommandManager.java index 6c25c28..de37d65 100644 --- a/blur-core/src/main/java/org/apache/blur/command/BaseCommandManager.java +++ b/blur-core/src/main/java/org/apache/blur/command/BaseCommandManager.java @@ -47,7 +47,7 @@ public class BaseCommandManager implements Closeable { private final ExecutorService _executorService; private final ExecutorService _executorServiceDriver; - + protected final Map<String, Command> _command = new ConcurrentHashMap<String, Command>(); protected final Map<Class<? extends Command>, String> _commandNameLookup = new ConcurrentHashMap<Class<? extends Command>, String>(); protected final ConcurrentMap<ExecutionId, Future<Response>> _runningMap; @@ -83,7 +83,7 @@ public class BaseCommandManager implements Closeable { } } - public Response reconnect(String executionId) throws IOException, TimeoutException { + public Response reconnect(ExecutionId executionId) throws IOException, TimeoutException { Future<Response> future = _runningMap.get(executionId); if (future == null) { throw new IOException("Command id [" + executionId + "] did not find any executing commands."); @@ -117,8 +117,8 @@ public class BaseCommandManager implements Closeable { } catch (ExecutionException e) { throw new IOException(e.getCause()); } catch (java.util.concurrent.TimeoutException e) { - LOG.info("Timeout of command [{0}]", executionId.getId()); - throw new TimeoutException(executionId.getId()); + LOG.info("Timeout of command [{0}]", executionId); + throw new TimeoutException(executionId); } } http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/3ae19454/blur-core/src/main/java/org/apache/blur/command/ExecutionId.java ---------------------------------------------------------------------- diff --git a/blur-core/src/main/java/org/apache/blur/command/ExecutionId.java b/blur-core/src/main/java/org/apache/blur/command/ExecutionId.java index a018d27..496d9cc 100644 --- a/blur-core/src/main/java/org/apache/blur/command/ExecutionId.java +++ b/blur-core/src/main/java/org/apache/blur/command/ExecutionId.java @@ -53,4 +53,9 @@ public class ExecutionId { return true; } + @Override + public String toString() { + return "ExecutionId [_id=" + _id + "]"; + } + } http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/3ae19454/blur-core/src/main/java/org/apache/blur/command/Response.java ---------------------------------------------------------------------- diff --git a/blur-core/src/main/java/org/apache/blur/command/Response.java b/blur-core/src/main/java/org/apache/blur/command/Response.java index d88dfe4..1b5f2e5 100644 --- a/blur-core/src/main/java/org/apache/blur/command/Response.java +++ b/blur-core/src/main/java/org/apache/blur/command/Response.java @@ -60,4 +60,11 @@ public class Response { public static Response createNewServerResponse(Map<Server, Object> result) { return new Response(null, null, result, false); } + + @Override + public String toString() { + return "Response [_shardResults=" + _shardResults + ", _serverResults=" + _serverResults + ", _serverResult=" + + _serverResult + ", _aggregatedResults=" + _aggregatedResults + "]"; + } + } http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/3ae19454/blur-core/src/main/java/org/apache/blur/command/ShardCommandManager.java ---------------------------------------------------------------------- diff --git a/blur-core/src/main/java/org/apache/blur/command/ShardCommandManager.java b/blur-core/src/main/java/org/apache/blur/command/ShardCommandManager.java index 6b5a1fd..16fdb4e 100644 --- a/blur-core/src/main/java/org/apache/blur/command/ShardCommandManager.java +++ b/blur-core/src/main/java/org/apache/blur/command/ShardCommandManager.java @@ -45,7 +45,7 @@ public class ShardCommandManager extends BaseCommandManager { public Response execute(final TableContext tableContext, final String commandName, final Args args) throws IOException, TimeoutException { - final ShardServerContext shardServerContext = ShardServerContext.getShardServerContext(); + final ShardServerContext shardServerContext = getShardServerContext(); Callable<Response> callable = new Callable<Response>() { @Override public Response call() throws Exception { @@ -64,6 +64,14 @@ public class ShardCommandManager extends BaseCommandManager { return submitDriverCallable(callable); } + private ShardServerContext getShardServerContext() { + ShardServerContext shardServerContext = ShardServerContext.getShardServerContext(); + if (shardServerContext == null) { + shardServerContext = new ShardServerContext(null, null); + } + return shardServerContext; + } + @SuppressWarnings("unchecked") private Response toResponse(Map<Shard, Object> results, Command command) throws IOException { if (command instanceof IndexReadCombiningCommand) { @@ -202,4 +210,9 @@ public class ShardCommandManager extends BaseCommandManager { } + public void cancel(ExecutionId executionId) { + // TODO + System.out.println("IMPLEMENT ME!!!!"); + } + } http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/3ae19454/blur-core/src/main/java/org/apache/blur/command/TimeoutException.java ---------------------------------------------------------------------- diff --git a/blur-core/src/main/java/org/apache/blur/command/TimeoutException.java b/blur-core/src/main/java/org/apache/blur/command/TimeoutException.java index b7b4530..a0b091f 100644 --- a/blur-core/src/main/java/org/apache/blur/command/TimeoutException.java +++ b/blur-core/src/main/java/org/apache/blur/command/TimeoutException.java @@ -19,13 +19,13 @@ package org.apache.blur.command; @SuppressWarnings("serial") public class TimeoutException extends Exception { - private final String _executionId; + private final ExecutionId _executionId; - public TimeoutException(String executionId) { + public TimeoutException(ExecutionId executionId) { _executionId = executionId; } - public String getExecutionId() { + public ExecutionId getExecutionId() { return _executionId; } http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/3ae19454/blur-core/src/main/java/org/apache/blur/server/BlurServerContext.java ---------------------------------------------------------------------- diff --git a/blur-core/src/main/java/org/apache/blur/server/BlurServerContext.java b/blur-core/src/main/java/org/apache/blur/server/BlurServerContext.java index 8061b38..8ddf078 100644 --- a/blur-core/src/main/java/org/apache/blur/server/BlurServerContext.java +++ b/blur-core/src/main/java/org/apache/blur/server/BlurServerContext.java @@ -40,8 +40,16 @@ public class BlurServerContext implements ServerContext, ThriftTrace { public BlurServerContext(SocketAddress localSocketAddress, SocketAddress remoteSocketAddress) { _localSocketAddress = localSocketAddress; _remoteSocketAddress = remoteSocketAddress; - _localConnectionString = _localSocketAddress.toString(); - _remoteConnectionString = _remoteSocketAddress.toString(); + if (_localSocketAddress != null) { + _localConnectionString = _localSocketAddress.toString(); + } else { + _localConnectionString = null; + } + if (_remoteSocketAddress != null) { + _remoteConnectionString = _remoteSocketAddress.toString(); + } else { + _remoteConnectionString = null; + } } public void setUser(User user) { http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/3ae19454/blur-core/src/main/java/org/apache/blur/thrift/BlurControllerServer.java ---------------------------------------------------------------------- diff --git a/blur-core/src/main/java/org/apache/blur/thrift/BlurControllerServer.java b/blur-core/src/main/java/org/apache/blur/thrift/BlurControllerServer.java index a8d6b45..28a46cd 100644 --- a/blur-core/src/main/java/org/apache/blur/thrift/BlurControllerServer.java +++ b/blur-core/src/main/java/org/apache/blur/thrift/BlurControllerServer.java @@ -49,6 +49,7 @@ import java.util.concurrent.atomic.AtomicReferenceArray; import org.apache.blur.command.CommandUtil; import org.apache.blur.command.ControllerCommandManager; +import org.apache.blur.command.ExecutionId; import org.apache.blur.command.Response; import org.apache.blur.concurrent.Executors; import org.apache.blur.log.Log; @@ -1510,12 +1511,12 @@ public class BlurControllerServer extends TableAdmin implements Iface { try { TableContext tableContext = getTableContext(table); Map<String, String> tableLayout = getTableLayout(table); - Response response = _commandManager.execute(tableContext, commandName, CommandUtil.toArgs(arguments), - tableLayout); + Response response = _commandManager + .execute(tableContext, commandName, CommandUtil.toArgs(arguments), tableLayout); return CommandUtil.fromObjectToThrift(response); } catch (Exception e) { if (e instanceof org.apache.blur.command.TimeoutException) { - throw new TimeoutException(((org.apache.blur.command.TimeoutException) e).getExecutionId()); + throw new TimeoutException(((org.apache.blur.command.TimeoutException) e).getExecutionId().getId()); } LOG.error("Unknown error while trying to execute command [{0}] for table [{1}]", e, commandName, table); if (e instanceof BlurException) { @@ -1533,11 +1534,11 @@ public class BlurControllerServer extends TableAdmin implements Iface { public org.apache.blur.thrift.generated.Response reconnect(String executionId) throws BlurException, TimeoutException, TException { try { - Response response = _commandManager.reconnect(executionId); + Response response = _commandManager.reconnect(new ExecutionId(executionId)); return CommandUtil.fromObjectToThrift(response); } catch (Exception e) { if (e instanceof org.apache.blur.command.TimeoutException) { - throw new TimeoutException(((org.apache.blur.command.TimeoutException) e).getExecutionId()); + throw new TimeoutException(((org.apache.blur.command.TimeoutException) e).getExecutionId().getId()); } LOG.error("Unknown error while trying to reconnect to executing command [{0}]", e, executionId); if (e instanceof BlurException) { @@ -1551,7 +1552,7 @@ public class BlurControllerServer extends TableAdmin implements Iface { public void refresh() throws TException { // This is a NO-OP at this point for the controller. } - + @Override public List<String> commandStatusList(int startingAt, short fetch, CommandStatusState state) throws BlurException, TException { http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/3ae19454/blur-core/src/main/java/org/apache/blur/thrift/BlurShardServer.java ---------------------------------------------------------------------- diff --git a/blur-core/src/main/java/org/apache/blur/thrift/BlurShardServer.java b/blur-core/src/main/java/org/apache/blur/thrift/BlurShardServer.java index 5579a50..5af713d 100644 --- a/blur-core/src/main/java/org/apache/blur/thrift/BlurShardServer.java +++ b/blur-core/src/main/java/org/apache/blur/thrift/BlurShardServer.java @@ -31,6 +31,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLongArray; import org.apache.blur.command.CommandUtil; +import org.apache.blur.command.ExecutionId; import org.apache.blur.command.Response; import org.apache.blur.command.ShardCommandManager; import org.apache.blur.concurrent.Executors; @@ -600,7 +601,7 @@ public class BlurShardServer extends TableAdmin implements Iface { return CommandUtil.fromObjectToThrift(response); } catch (Exception e) { if (e instanceof org.apache.blur.command.TimeoutException) { - throw new TimeoutException(((org.apache.blur.command.TimeoutException) e).getExecutionId()); + throw new TimeoutException(((org.apache.blur.command.TimeoutException) e).getExecutionId().getId()); } LOG.error("Unknown error while trying to execute command [{0}] for table [{1}]", e, commandName, table); if (e instanceof BlurException) { @@ -622,11 +623,11 @@ public class BlurShardServer extends TableAdmin implements Iface { public org.apache.blur.thrift.generated.Response reconnect(String executionId) throws BlurException, TimeoutException, TException { try { - Response response = _commandManager.reconnect(executionId); + Response response = _commandManager.reconnect(new ExecutionId(executionId)); return CommandUtil.fromObjectToThrift(response); } catch (Exception e) { if (e instanceof org.apache.blur.command.TimeoutException) { - throw new TimeoutException(((org.apache.blur.command.TimeoutException) e).getExecutionId()); + throw new TimeoutException(((org.apache.blur.command.TimeoutException) e).getExecutionId().getId()); } LOG.error("Unknown error while trying to reconnect to executing command [{0}]", e, executionId); if (e instanceof BlurException) { http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/3ae19454/blur-core/src/test/java/org/apache/blur/command/BlurArrayTest.java ---------------------------------------------------------------------- diff --git a/blur-core/src/test/java/org/apache/blur/command/BlurArrayTest.java b/blur-core/src/test/java/org/apache/blur/command/BlurArrayTest.java new file mode 100644 index 0000000..44888e6 --- /dev/null +++ b/blur-core/src/test/java/org/apache/blur/command/BlurArrayTest.java @@ -0,0 +1,61 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.blur.command; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + +import org.apache.blur.command.BlurArray; +import org.junit.Test; + +public class BlurArrayTest { + + @Test + public void testPutAndLength() { + BlurArray array = new BlurArray(); + assertEquals(0, array.length()); + array.put("v"); + assertEquals(1, array.length()); + assertEquals("v", array.getObject(0)); + } + + @Test + public void testArrayOutOfBounds() { + BlurArray array = new BlurArray(); + try { + array.getObject(123); + fail(); + } catch (IndexOutOfBoundsException e) { + // Pass + } + } + + @Test + public void testSettingValues() { + BlurArray array = new BlurArray(); + array.put(1, "a"); + assertEquals("a", array.getObject(1)); + assertEquals(2, array.length()); + assertNull(array.getObject(0)); + array.put(1, "b"); + assertEquals("b", array.getObject(1)); + assertEquals(2, array.length()); + assertNull(array.getObject(0)); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/3ae19454/blur-core/src/test/java/org/apache/blur/command/ShardCommandManagerTest.java ---------------------------------------------------------------------- diff --git a/blur-core/src/test/java/org/apache/blur/command/ShardCommandManagerTest.java b/blur-core/src/test/java/org/apache/blur/command/ShardCommandManagerTest.java new file mode 100644 index 0000000..72570aa --- /dev/null +++ b/blur-core/src/test/java/org/apache/blur/command/ShardCommandManagerTest.java @@ -0,0 +1,258 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.blur.command; + +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.SortedSet; +import java.util.concurrent.atomic.AtomicBoolean; + +import org.apache.blur.manager.IndexServer; +import org.apache.blur.manager.writer.BlurIndex; +import org.apache.blur.manager.writer.IndexAction; +import org.apache.blur.server.IndexSearcherClosable; +import org.apache.blur.server.ShardContext; +import org.apache.blur.server.TableContext; +import org.apache.blur.thrift.generated.RowMutation; +import org.apache.blur.thrift.generated.ShardState; +import org.apache.blur.thrift.generated.TableDescriptor; +import org.apache.blur.utils.BlurUtil; +import org.apache.lucene.analysis.core.KeywordAnalyzer; +import org.apache.lucene.index.DirectoryReader; +import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.IndexWriter; +import org.apache.lucene.index.IndexWriterConfig; +import org.apache.lucene.store.Directory; +import org.apache.lucene.store.RAMDirectory; +import org.apache.lucene.util.Version; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class ShardCommandManagerTest { + + private static final Directory EMPTY_INDEX; + + static { + EMPTY_INDEX = new RAMDirectory(); + IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_43, new KeywordAnalyzer()); + try { + new IndexWriter(EMPTY_INDEX, conf).close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private ShardCommandManager _manager; + + @Before + public void setup() throws IOException { + _manager = new ShardCommandManager(getIndexServer(), 10, 1000); + } + + @After + public void teardown() throws IOException { + _manager.close(); + } + + @Test + public void testShardCommandManagerNormalWait() throws IOException, TimeoutException { + TableContext tableContext = getTableContext(); + Response response; + ExecutionId executionId = null; + + Args args = new Args(); + args.set("seconds", 5); + + while (true) { + try { + if (executionId == null) { + response = _manager.execute(tableContext, "wait", args); + } else { + response = _manager.reconnect(executionId); + } + break; + } catch (TimeoutException te) { + executionId = te.getExecutionId(); + } + } + System.out.println(response); + } + + @Test + public void testShardCommandManagerNormalWithCancel() throws IOException, TimeoutException { + TableContext tableContext = getTableContext(); + Response response; + ExecutionId executionId = null; + + Args args = new Args(); + args.set("seconds", 5); + + try { + response = _manager.execute(tableContext, "wait", args); + } catch (TimeoutException te) { + _manager.cancel(te.getExecutionId()); + // some how validate the threads have cancelled. + } + + } + + private TableContext getTableContext() { + return TableContext.create(getTableDescriptor()); + } + + private TableDescriptor getTableDescriptor() { + TableDescriptor tableDescriptor = new TableDescriptor(); + tableDescriptor.setName("test"); + tableDescriptor.setShardCount(3); + tableDescriptor.setTableUri("file:///tmp/"); + return tableDescriptor; + } + + private IndexServer getIndexServer() { + return new IndexServer() { + @Override + public Map<String, BlurIndex> getIndexes(String table) throws IOException { + Map<String, BlurIndex> indexes = new HashMap<String, BlurIndex>(); + for (int i = 0; i < 3; i++) { + String shardName = BlurUtil.getShardName(i); + indexes.put(shardName, getNullBlurIndex(shardName)); + } + return indexes; + } + + @Override + public long getTableSize(String table) throws IOException { + throw new RuntimeException("Not implemented."); + } + + @Override + public Map<String, ShardState> getShardState(String table) { + throw new RuntimeException("Not implemented."); + } + + @Override + public SortedSet<String> getShardListCurrentServerOnly(String table) throws IOException { + throw new RuntimeException("Not implemented."); + } + + @Override + public List<String> getShardList(String table) { + throw new RuntimeException("Not implemented."); + } + + @Override + public long getRowCount(String table) throws IOException { + throw new RuntimeException("Not implemented."); + } + + @Override + public long getRecordCount(String table) throws IOException { + throw new RuntimeException("Not implemented."); + } + + @Override + public String getNodeName() { + throw new RuntimeException("Not implemented."); + } + + @Override + public void close() throws IOException { + throw new RuntimeException("Not implemented."); + } + }; + } + + protected BlurIndex getNullBlurIndex(String shard) throws IOException { + ShardContext shardContext = ShardContext.create(getTableContext(), shard); + return new BlurIndex(shardContext, null, null, null, null, null) { + + @Override + public void removeSnapshot(String name) throws IOException { + throw new RuntimeException("Not implemented."); + } + + @Override + public void refresh() throws IOException { + throw new RuntimeException("Not implemented."); + } + + @Override + public void process(IndexAction indexAction) throws IOException { + throw new RuntimeException("Not implemented."); + } + + @Override + public void optimize(int numberOfSegmentsPerShard) throws IOException { + throw new RuntimeException("Not implemented."); + } + + @Override + public AtomicBoolean isClosed() { + throw new RuntimeException("Not implemented."); + } + + @Override + public List<String> getSnapshots() throws IOException { + throw new RuntimeException("Not implemented."); + } + + @Override + public IndexSearcherClosable getIndexSearcher() throws IOException { + IndexReader reader = getEmtpyReader(); + return new IndexSearcherClosable(reader, null) { + + @Override + public Directory getDirectory() { + return getEmtpyDirectory(); + } + + @Override + public void close() throws IOException { + + } + }; + } + + @Override + public void enqueue(List<RowMutation> mutations) throws IOException { + throw new RuntimeException("Not implemented."); + } + + @Override + public void createSnapshot(String name) throws IOException { + throw new RuntimeException("Not implemented."); + } + + @Override + public void close() throws IOException { + throw new RuntimeException("Not implemented."); + } + }; + } + + protected IndexReader getEmtpyReader() throws IOException { + return DirectoryReader.open(getEmtpyDirectory()); + } + + protected Directory getEmtpyDirectory() { + return EMPTY_INDEX; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/3ae19454/blur-core/src/test/java/org/apache/blur/command/WaitForSeconds.java ---------------------------------------------------------------------- diff --git a/blur-core/src/test/java/org/apache/blur/command/WaitForSeconds.java b/blur-core/src/test/java/org/apache/blur/command/WaitForSeconds.java new file mode 100644 index 0000000..eeecf86 --- /dev/null +++ b/blur-core/src/test/java/org/apache/blur/command/WaitForSeconds.java @@ -0,0 +1,46 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.blur.command; + +import java.io.IOException; +import java.util.concurrent.TimeUnit; + +import org.apache.blur.command.Command; +import org.apache.blur.command.IndexContext; +import org.apache.blur.command.IndexReadCommand; + +@SuppressWarnings("serial") +public class WaitForSeconds extends Command implements IndexReadCommand<Boolean> { + + @Override + public Boolean execute(IndexContext context) throws IOException { + Args args = context.getArgs(); + int seconds = args.get("seconds", 30); + try { + Thread.sleep(TimeUnit.SECONDS.toMillis(seconds)); + } catch (InterruptedException e) { + throw new IOException(e); + } + return true; + } + + @Override + public String getName() { + return "wait"; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/3ae19454/blur-core/src/test/java/org/apache/blur/manager/command/BlurArrayTest.java ---------------------------------------------------------------------- diff --git a/blur-core/src/test/java/org/apache/blur/manager/command/BlurArrayTest.java b/blur-core/src/test/java/org/apache/blur/manager/command/BlurArrayTest.java deleted file mode 100644 index acdb9cc..0000000 --- a/blur-core/src/test/java/org/apache/blur/manager/command/BlurArrayTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.blur.manager.command; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; - -import org.apache.blur.command.BlurArray; -import org.junit.Test; - -public class BlurArrayTest { - - @Test - public void testPutAndLength() { - BlurArray array = new BlurArray(); - assertEquals(0, array.length()); - array.put("v"); - assertEquals(1, array.length()); - assertEquals("v", array.getObject(0)); - } - - @Test - public void testArrayOutOfBounds() { - BlurArray array = new BlurArray(); - try { - array.getObject(123); - fail(); - } catch (IndexOutOfBoundsException e) { - // Pass - } - } - - @Test - public void testSettingValues() { - BlurArray array = new BlurArray(); - array.put(1, "a"); - assertEquals("a", array.getObject(1)); - assertEquals(2, array.length()); - assertNull(array.getObject(0)); - array.put(1, "b"); - assertEquals("b", array.getObject(1)); - assertEquals(2, array.length()); - assertNull(array.getObject(0)); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/3ae19454/blur-core/src/test/resources/META-INF/services/org.apache.blur.command.Commands ---------------------------------------------------------------------- diff --git a/blur-core/src/test/resources/META-INF/services/org.apache.blur.command.Commands b/blur-core/src/test/resources/META-INF/services/org.apache.blur.command.Commands new file mode 100644 index 0000000..51c8777 --- /dev/null +++ b/blur-core/src/test/resources/META-INF/services/org.apache.blur.command.Commands @@ -0,0 +1,16 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +org.apache.blur.command.WaitForSeconds \ No newline at end of file
