@Override public int run(String[] args) throws Exception { if (args.length != 3) { throw new IllegalArgumentException( "Usage : " + MRTester.class.getName() + " <user> <pass> <table>"); } String user = args[0]; String pass = args[1]; String table = args[2]; @SuppressWarnings("deprecation") Job job = new Job(getConf(), this.getClass().getSimpleName() + "_" + System.currentTimeMillis()); job.setJarByClass(this.getClass()); job.setInputFormatClass(AccumuloInputFormat.class); AccumuloInputFormat.setConnectorInfo(job, user, new PasswordToken(pass)); AccumuloInputFormat.setInputTableName(job, table); AccumuloInputFormat.setMockInstance(job, INSTANCE_NAME); job.setMapperClass(TestMapper.class); job.setMapOutputKeyClass(Key.class); job.setMapOutputValueClass(Value.class); job.setOutputFormatClass(NullOutputFormat.class); job.setNumReduceTasks(0); job.waitForCompletion(true); return job.isSuccessful() ? 0 : 1; }
/** * Test adding iterator options where the keys and values contain both the FIELD_SEPARATOR * character (':') and ITERATOR_SEPARATOR (',') characters. There should be no exceptions thrown * when trying to parse these types of option entries. * * <p>This test makes sure that the expected raw values, as appears in the Job, are equal to * what's expected. */ @Test public void testIteratorOptionEncoding() throws Throwable { String key = "colon:delimited:key"; String value = "comma,delimited,value"; IteratorSetting someSetting = new IteratorSetting(1, "iterator", "Iterator.class"); someSetting.addOption(key, value); @SuppressWarnings("deprecation") Job job = new Job(); AccumuloInputFormat.addIterator(job, someSetting); List<IteratorSetting> list = AccumuloInputFormat.getIterators(job); assertEquals(1, list.size()); assertEquals(1, list.get(0).getOptions().size()); assertEquals(list.get(0).getOptions().get(key), value); someSetting.addOption(key + "2", value); someSetting.setPriority(2); someSetting.setName("it2"); AccumuloInputFormat.addIterator(job, someSetting); list = AccumuloInputFormat.getIterators(job); assertEquals(2, list.size()); assertEquals(1, list.get(0).getOptions().size()); assertEquals(list.get(0).getOptions().get(key), value); assertEquals(2, list.get(1).getOptions().size()); assertEquals(list.get(1).getOptions().get(key), value); assertEquals(list.get(1).getOptions().get(key + "2"), value); }
@Test public void testSetRegex() throws IOException { @SuppressWarnings("deprecation") Job job = new Job(); String regex = ">\"*%<>\'\\"; IteratorSetting is = new IteratorSetting(50, regex, RegExFilter.class); RegExFilter.setRegexs(is, regex, null, null, null, false); AccumuloInputFormat.addIterator(job, is); assertTrue(regex.equals(AccumuloInputFormat.getIterators(job).get(0).getName())); }
@Test public void testAddIterator() throws IOException { @SuppressWarnings("deprecation") Job job = new Job(); AccumuloInputFormat.addIterator( job, new IteratorSetting(1, "WholeRow", WholeRowIterator.class)); AccumuloInputFormat.addIterator( job, new IteratorSetting( 2, "Versions", "org.apache.accumulo.core.iterators.VersioningIterator")); IteratorSetting iter = new IteratorSetting(3, "Count", "org.apache.accumulo.core.iterators.CountingIterator"); iter.addOption("v1", "1"); iter.addOption("junk", "\0omg:!\\xyzzy"); AccumuloInputFormat.addIterator(job, iter); List<IteratorSetting> list = AccumuloInputFormat.getIterators(job); // Check the list size assertTrue(list.size() == 3); // Walk the list and make sure our settings are correct IteratorSetting setting = list.get(0); assertEquals(1, setting.getPriority()); assertEquals( "org.apache.accumulo.core.iterators.user.WholeRowIterator", setting.getIteratorClass()); assertEquals("WholeRow", setting.getName()); assertEquals(0, setting.getOptions().size()); setting = list.get(1); assertEquals(2, setting.getPriority()); assertEquals( "org.apache.accumulo.core.iterators.VersioningIterator", setting.getIteratorClass()); assertEquals("Versions", setting.getName()); assertEquals(0, setting.getOptions().size()); setting = list.get(2); assertEquals(3, setting.getPriority()); assertEquals("org.apache.accumulo.core.iterators.CountingIterator", setting.getIteratorClass()); assertEquals("Count", setting.getName()); assertEquals(2, setting.getOptions().size()); assertEquals("1", setting.getOptions().get("v1")); assertEquals("\0omg:!\\xyzzy", setting.getOptions().get("junk")); }
/** * Check that the iterator configuration is getting stored in the Job conf correctly. * * @throws IOException */ @Test public void testSetIterator() throws IOException { @SuppressWarnings("deprecation") Job job = new Job(); IteratorSetting is = new IteratorSetting(1, "WholeRow", "org.apache.accumulo.core.iterators.WholeRowIterator"); AccumuloInputFormat.addIterator(job, is); Configuration conf = job.getConfiguration(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); is.write(new DataOutputStream(baos)); String iterators = conf.get("AccumuloInputFormat.ScanOpts.Iterators"); assertEquals(new String(Base64.encodeBase64(baos.toByteArray())), iterators); }