Updated Branches: refs/heads/1.6.0-SNAPSHOT 46585ab59 -> b54b13049
ACCUMULO-2037 quick test to verify locality, location state management Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/741c83ca Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/741c83ca Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/741c83ca Branch: refs/heads/1.6.0-SNAPSHOT Commit: 741c83ca1a87dac227ddc783e94dab1924716658 Parents: 46585ab Author: Eric Newton <eric.new...@gmail.com> Authored: Tue Dec 17 15:05:33 2013 -0500 Committer: Eric Newton <eric.new...@gmail.com> Committed: Tue Dec 17 15:05:33 2013 -0500 ---------------------------------------------------------------------- .../test/functional/MasterAssignmentIT.java | 88 ++++++++++++++++++++ 1 file changed, 88 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/accumulo/blob/741c83ca/test/src/test/java/org/apache/accumulo/test/functional/MasterAssignmentIT.java ---------------------------------------------------------------------- diff --git a/test/src/test/java/org/apache/accumulo/test/functional/MasterAssignmentIT.java b/test/src/test/java/org/apache/accumulo/test/functional/MasterAssignmentIT.java new file mode 100644 index 0000000..01bbd73 --- /dev/null +++ b/test/src/test/java/org/apache/accumulo/test/functional/MasterAssignmentIT.java @@ -0,0 +1,88 @@ +/* + * 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.accumulo.test.functional; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import org.apache.accumulo.core.client.BatchWriter; +import org.apache.accumulo.core.client.BatchWriterConfig; +import org.apache.accumulo.core.client.Connector; +import org.apache.accumulo.core.client.security.tokens.PasswordToken; +import org.apache.accumulo.core.data.KeyExtent; +import org.apache.accumulo.core.data.Mutation; +import org.apache.accumulo.core.data.Range; +import org.apache.accumulo.core.security.Credentials; +import org.apache.accumulo.fate.util.UtilWaitThread; +import org.apache.accumulo.server.master.state.MetaDataTableScanner; +import org.apache.accumulo.server.master.state.TabletLocationState; +import org.apache.hadoop.io.Text; +import org.junit.Test; + +public class MasterAssignmentIT extends SimpleMacIT { + + @Test(timeout=2*60*1000) + public void test() throws Exception { + Connector c = getConnector(); + String tableName = super.getTableNames(1)[0]; + c.tableOperations().create(tableName); + String tableId = c.tableOperations().tableIdMap().get(tableName); + // wait for the table to be online + TabletLocationState newTablet; + do { + UtilWaitThread.sleep(250); + newTablet = getTabletLocationState(c, tableId); + } while (newTablet.current == null); + assertNull(newTablet.last); + assertNull(newTablet.future); + + // put something in it + BatchWriter bw = c.createBatchWriter(tableName, new BatchWriterConfig()); + Mutation m = new Mutation("a"); + m.put("b", "c", "d"); + bw.addMutation(m); + bw.close(); + // give it a last location + c.tableOperations().flush(tableName, null, null, true); + + TabletLocationState flushed = getTabletLocationState(c, tableId); + assertEquals(newTablet.current, flushed.current); + assertEquals(flushed.current, flushed.last); + assertNull(newTablet.future); + + // take the tablet offline + c.tableOperations().offline(tableName, true); + TabletLocationState offline = getTabletLocationState(c, tableId); + assertNull(offline.future); + assertNull(offline.current); + assertEquals(flushed.current, offline.last); + + // put it back online + c.tableOperations().online(tableName, true); + TabletLocationState online = getTabletLocationState(c, tableId); + assertNull(online.future); + assertNotNull(online.current); + assertEquals(online.current, online.last); + } + + private TabletLocationState getTabletLocationState(Connector c, String tableId) { + Credentials creds = new Credentials("root", new PasswordToken(ROOT_PASSWORD)); + MetaDataTableScanner s = new MetaDataTableScanner(c.getInstance(), creds, new Range(KeyExtent.getMetadataEntry(new Text(tableId), null))); + return s.next(); + } +}