use of org.apache.accumulo.core.client.BatchWriter in project accumulo by apache.
the class AccumuloFileOutputFormatIT method setup.
@Before
public void setup() throws Exception {
PREFIX = testName.getMethodName() + "_";
BAD_TABLE = PREFIX + "_mapreduce_bad_table";
TEST_TABLE = PREFIX + "_mapreduce_test_table";
EMPTY_TABLE = PREFIX + "_mapreduce_empty_table";
Connector c = getConnector();
c.tableOperations().create(EMPTY_TABLE);
c.tableOperations().create(TEST_TABLE);
c.tableOperations().create(BAD_TABLE);
BatchWriter bw = c.createBatchWriter(TEST_TABLE, new BatchWriterConfig());
Mutation m = new Mutation("Key");
m.put("", "", "");
bw.addMutation(m);
bw.close();
bw = c.createBatchWriter(BAD_TABLE, new BatchWriterConfig());
m = new Mutation("r1");
m.put("cf1", "cq1", "A&B");
m.put("cf1", "cq1", "A&B");
m.put("cf1", "cq2", "A&");
bw.addMutation(m);
bw.close();
}
use of org.apache.accumulo.core.client.BatchWriter in project accumulo by apache.
the class AccumuloInputFormatIT method testMapWithBatchScanner.
@Test
public void testMapWithBatchScanner() throws Exception {
final String TEST_TABLE_2 = getUniqueNames(1)[0];
Connector c = getConnector();
c.tableOperations().create(TEST_TABLE_2);
BatchWriter bw = c.createBatchWriter(TEST_TABLE_2, new BatchWriterConfig());
for (int i = 0; i < 100; i++) {
Mutation m = new Mutation(new Text(String.format("%09x", i + 1)));
m.put(new Text(), new Text(), new Value(String.format("%09x", i).getBytes()));
bw.addMutation(m);
}
bw.close();
Assert.assertEquals(0, MRTester.main(new String[] { TEST_TABLE_2, AccumuloInputFormat.class.getName(), "True", "False" }));
assertEquals(1, assertionErrors.get(TEST_TABLE_2 + "_map").size());
assertEquals(1, assertionErrors.get(TEST_TABLE_2 + "_cleanup").size());
}
use of org.apache.accumulo.core.client.BatchWriter in project accumulo by apache.
the class AccumuloRowInputFormatIT method test.
@Test
public void test() throws Exception {
final Connector conn = getConnector();
String tableName = getUniqueNames(1)[0];
conn.tableOperations().create(tableName);
BatchWriter writer = null;
try {
writer = conn.createBatchWriter(tableName, new BatchWriterConfig());
insertList(writer, row1);
insertList(writer, row2);
insertList(writer, row3);
} finally {
if (writer != null) {
writer.close();
}
}
MRTester.main(new String[] { tableName });
assertNull(e1);
assertNull(e2);
}
use of org.apache.accumulo.core.client.BatchWriter in project accumulo by apache.
the class SessionBlockVerifyIT method run.
@Test
public void run() throws Exception {
Connector c = getConnector();
String tableName = getUniqueNames(1)[0];
c.tableOperations().create(tableName);
BatchWriter bw = c.createBatchWriter(tableName, new BatchWriterConfig());
for (int i = 0; i < 1000; i++) {
Mutation m = new Mutation(new Text(String.format("%08d", i)));
for (int j = 0; j < 3; j++) m.put(new Text("cf1"), new Text("cq" + j), new Value((i + "_" + j).getBytes(UTF_8)));
bw.addMutation(m);
}
bw.close();
try (Scanner scanner = c.createScanner(tableName, new Authorizations())) {
scanner.setReadaheadThreshold(20000);
scanner.setRange(new Range(String.format("%08d", 0), String.format("%08d", 1000)));
// test by making a slow iterator and then a couple of fast ones.
// when then checking we shouldn't have any running except the slow iterator
IteratorSetting setting = new IteratorSetting(21, SlowIterator.class);
SlowIterator.setSeekSleepTime(setting, Long.MAX_VALUE);
SlowIterator.setSleepTime(setting, Long.MAX_VALUE);
scanner.addScanIterator(setting);
final Iterator<Entry<Key, Value>> slow = scanner.iterator();
final List<Future<Boolean>> callables = new ArrayList<>();
final CountDownLatch latch = new CountDownLatch(10);
for (int i = 0; i < 10; i++) {
Future<Boolean> callable = service.submit(new Callable<Boolean>() {
public Boolean call() {
latch.countDown();
while (slow.hasNext()) {
slow.next();
}
return slow.hasNext();
}
});
callables.add(callable);
}
latch.await();
log.info("Starting SessionBlockVerifyIT");
// let's add more for good measure.
for (int i = 0; i < 2; i++) {
try (Scanner scanner2 = c.createScanner(tableName, new Authorizations())) {
scanner2.setRange(new Range(String.format("%08d", 0), String.format("%08d", 1000)));
scanner2.setBatchSize(1);
Iterator<Entry<Key, Value>> iter = scanner2.iterator();
// call super's verify mechanism
verify(iter, 0, 1000);
}
}
int sessionsFound = 0;
// we have configured 1 tserver, so we can grab the one and only
String tserver = Iterables.getOnlyElement(c.instanceOperations().getTabletServers());
final List<ActiveScan> scans = c.instanceOperations().getActiveScans(tserver);
for (ActiveScan scan : scans) {
if (tableName.equals(scan.getTable()) && scan.getSsiList().size() > 0) {
assertEquals("Not the expected iterator", 1, scan.getSsiList().size());
assertTrue("Not the expected iterator", scan.getSsiList().iterator().next().contains("SlowIterator"));
sessionsFound++;
}
}
/**
* The message below indicates the problem that we experience within ACCUMULO-3509. The issue manifests as a blockage in the Scanner synchronization that
* prevent us from making the close call against it. Since the close blocks until a read is finished, we ultimately have a block within the sweep of
* SessionManager. As a result never reap subsequent idle sessions AND we will orphan the sessionsToCleanup in the sweep, leading to an inaccurate count
* within sessionsFound.
*/
assertEquals("Must have ten sessions. Failure indicates a synchronization block within the sweep mechanism", 10, sessionsFound);
for (Future<Boolean> callable : callables) {
callable.cancel(true);
}
}
service.shutdown();
}
use of org.apache.accumulo.core.client.BatchWriter in project accumulo by apache.
the class SessionDurabilityIT method writeSome.
private void writeSome(String tableName, int n, BatchWriterConfig cfg) throws Exception {
Connector c = getConnector();
BatchWriter bw = c.createBatchWriter(tableName, cfg);
for (int i = 0; i < n; i++) {
Mutation m = new Mutation(i + "");
m.put("", "", "");
bw.addMutation(m);
}
bw.close();
}
Aggregations