List of usage examples for org.apache.hadoop.io ArrayWritable set
public void set(Writable[] values)
From source file:org.apache.hama.bsp.TestZooKeeper.java
License:Apache License
@Test public void testClearZKNodes() throws IOException, KeeperException, InterruptedException { final ZooKeeperSyncServerImpl server = new ZooKeeperSyncServerImpl(); boolean done = false; try {/*from ww w .j av a2s .c o m*/ server.init(configuration); ExecutorService executorService = Executors.newCachedThreadPool(); executorService.submit(new Runnable() { @Override public void run() { try { server.start(); } catch (Exception e) { e.printStackTrace(); } } }); executorService.awaitTermination(10, TimeUnit.SECONDS); String bspRoot = "/bsp"; ZooKeeperSyncClientImpl peerClient = (ZooKeeperSyncClientImpl) SyncServiceFactory .getPeerSyncClient(configuration); ZKSyncBSPMasterClient masterClient = (ZKSyncBSPMasterClient) SyncServiceFactory .getMasterSyncClient(configuration); masterClient.init(configuration); Thread.sleep(100); Log.info("Created master and client sync clients"); assertTrue(masterClient.hasKey(bspRoot)); Log.info("BSP root exists"); BSPJobID jobID = new BSPJobID("test1", 1); masterClient.registerJob(jobID.toString()); TaskID taskId1 = new TaskID(jobID, 1); TaskID taskId2 = new TaskID(jobID, 2); TaskAttemptID task1 = new TaskAttemptID(taskId1, 1); TaskAttemptID task2 = new TaskAttemptID(taskId2, 1); int zkPort = BSPNetUtils.getFreePort(21815); configuration.setInt(Constants.PEER_PORT, zkPort); peerClient.init(configuration, jobID, task1); peerClient.registerTask(jobID, "hamanode1", 5000L, task1); peerClient.registerTask(jobID, "hamanode2", 5000L, task2); peerClient.storeInformation(peerClient.constructKey(jobID, "info", "level2"), new IntWritable(5), true, null); String[] names = peerClient.getAllPeerNames(task1.getJobID()); Log.info("Found child count = " + names.length); assertEquals(2, names.length); Log.info("Passed the child count test"); masterClient.addKey(masterClient.constructKey(jobID, "peer", "1"), true, null); masterClient.addKey(masterClient.constructKey(jobID, "peer", "2"), true, null); String[] peerChild = masterClient.getChildKeySet(masterClient.constructKey(jobID, "peer"), null); Log.info("Found child count = " + peerChild.length); assertEquals(2, peerChild.length); Log.info(" Peer name " + peerChild[0]); Log.info(" Peer name " + peerChild[1]); Log.info("Passed the child key set test"); masterClient.deregisterJob(jobID.toString()); Log.info(masterClient.constructKey(jobID)); Thread.sleep(200); assertEquals(false, masterClient.hasKey(masterClient.constructKey(jobID))); Log.info("Passed the key presence test"); boolean result = masterClient.getInformation(masterClient.constructKey(jobID, "info", "level3"), new IntWritable()); assertEquals(false, result); Writable[] writableArr = new Writable[2]; writableArr[0] = new LongWritable(3L); writableArr[1] = new LongWritable(5L); ArrayWritable arrWritable = new ArrayWritable(LongWritable.class); arrWritable.set(writableArr); masterClient.storeInformation(masterClient.constructKey(jobID, "info", "level3"), arrWritable, true, null); ArrayWritable valueHolder = new ArrayWritable(LongWritable.class); boolean getResult = masterClient.getInformation(masterClient.constructKey(jobID, "info", "level3"), valueHolder); assertTrue(getResult); assertEquals(arrWritable.get()[0], valueHolder.get()[0]); assertEquals(arrWritable.get()[1], valueHolder.get()[1]); Log.info("Passed array writable test"); done = true; } catch (Exception e) { e.printStackTrace(); } finally { server.stopServer(); } assertEquals(true, done); }
From source file:org.huahinframework.core.io.RecordTest.java
License:Apache License
@Test public void testValueTextArray() { Record record = new Record(); ArrayWritable o = new ArrayWritable(Text.class); Writable[] w = { new Text("String1"), new Text("String2"), new Text("String3") }; o.set(w); record.addValue("Object", o); assertEquals(record.getValueArrayWritable("Object"), o); assertEquals(record.getValueArrayWritable("Object").get().length, 3); assertEquals(record.getValueArrayWritable("Object").get()[0], new Text("String1")); assertEquals(record.getValueArrayWritable("Object").get()[1], new Text("String2")); assertEquals(record.getValueArrayWritable("Object").get()[2], new Text("String3")); assertEquals(record.getValueArrayWritable("Object2"), null); try {/*from w ww .j av a 2s.c o m*/ record.getValueInteger("Object"); fail("fail ClassCastException"); } catch (Exception e) { assertTrue(e instanceof ClassCastException); } }
From source file:org.huahinframework.core.io.RecordTest.java
License:Apache License
@Test public void testValueIntWritableArray() { Record record = new Record(); ArrayWritable o = new ArrayWritable(Text.class); Writable[] w = { new IntWritable(1), new IntWritable(2), new IntWritable(3) }; o.set(w); record.addValue("Object", o); assertEquals(record.getValueArrayWritable("Object"), o); assertEquals(record.getValueArrayWritable("Object").get().length, 3); assertEquals(record.getValueArrayWritable("Object").get()[0], new IntWritable(1)); assertEquals(record.getValueArrayWritable("Object").get()[1], new IntWritable(2)); assertEquals(record.getValueArrayWritable("Object").get()[2], new IntWritable(3)); assertEquals(record.getValueArrayWritable("Object2"), null); try {//from w w w. j a v a2s . co m record.getValueInteger("Object"); fail("fail ClassCastException"); } catch (Exception e) { assertTrue(e instanceof ClassCastException); } }
From source file:org.zuinnote.hadoop.office.format.mapred.ExcelRecordReader.java
License:Apache License
/** * * Create an empty value/*from w ww .j a v a 2s . co m*/ * * @return value */ @Override public ArrayWritable createValue() { ArrayWritable newArrayWritable = new ArrayWritable(SpreadSheetCellDAO.class); newArrayWritable.set(new SpreadSheetCellDAO[0]); return newArrayWritable; }
From source file:org.zuinnote.hadoop.office.format.mapred.ExcelRecordReader.java
License:Apache License
/** * * Read row from Office document. If document does not match a defined metadata filter then it returns no rows. If no metadata filter is defined or document matches metadata filter then it returns rows, if available in the document/selected sheet * * @return true if next more rows are available, false if not *//*from w w w . java 2 s.c om*/ @Override public boolean next(Text key, ArrayWritable value) throws IOException { if (!(this.getOfficeReader().getFiltered())) { return false; } Object[] objectArray = this.getOfficeReader().getNext(); if (objectArray == null) { return false; // no more to read } SpreadSheetCellDAO[] cellRows = (SpreadSheetCellDAO[]) objectArray; key.set("[" + this.split.getPath().getName() + "]" + this.getOfficeReader().getCurrentSheetName() + "!A" + this.getOfficeReader().getCurrentRow()); value.set(cellRows); return true; }