| <!-- |
| 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. |
| --> |
| <html> |
| <head> |
| <title>Accumulo Mock</title> |
| <link rel='stylesheet' type='text/css' href='documentation.css' media='screen'/> |
| </head> |
| <body> |
| |
| <h1>Apache Accumulo Documentation : Mock Accumulo</h1> |
| |
| <p>Normally, accumulo consists of lots of moving parts. Even a stand-alone version of accumulo requires hadoop, |
| zookeeper, the accumulo master, a tablet server, etc. If you want to write a unit test that uses accumulo, you need a lot of |
| infrastructure in place before your test can run. To help developers with their tests, we have created a fake version of |
| Accumulo called MockAccumulo. The normal interaction with the client API looks something like this: |
| </p> |
| |
| <pre> |
| Instance instance = new ZooKeeperInstance(...); |
| Connector conn = instance.getConnector(user, passwd); |
| BatchScanner scanner = conn.createBatchScaner(...); |
| // configure scanner |
| // ... |
| for (Entry<Key, Value> entry : scanner) { |
| // process entry |
| } |
| </pre> |
| |
| <p>MockAccumulo supports the same client API. Just replace the ZooKeeperInstance with MockInstance:</p> |
| |
| <pre> |
| Instance instance = new MockInstance(); |
| // as above |
| </pre> |
| |
| <p>In fact, you can use the <tt>--fake</tt> option to the accumulo shell and interact with MockAccumulo:</p> |
| |
| <pre> |
| $ ./bin/accumulo shell --fake -u root -p nonsense |
| |
| Shell - Apache Accumulo Interactive Shell |
| - |
| - version: 1.3.2-SNAPSHOT |
| - instance name: mock-instance |
| - instance id: mock-instance-id |
| - |
| - type 'help' for a list of available commands |
| - |
| root@mock-instance> createtable test |
| root@mock-instance test> insert row1 cf cq value |
| root@mock-instance test> insert row2 cf cq value2 |
| root@mock-instance test> insert row3 cf cq value3 |
| root@mock-instance test> scan |
| row1 cf:cq [] value |
| row2 cf:cq [] value2 |
| row3 cf:cq [] value3 |
| root@mock-instance test> scan -b row2 -e row2 |
| row2 cf:cq [] value2 |
| root@mock-instance test> |
| </pre> |
| |
| <p>MockAccumulo presently does not enforce users, logins, permissions, etc. It <b>does</b> support Iterators and Aggregators. |
| Note that MockAccumulo holds all data in memory, and will not retain any data or settings between runs.</p> |
| |
| </body> |
| </html> |