@Override public Void method(Void nothing) throws RemoteException { Parcel data = Parcel.obtain(); Parcel reply = Parcel.obtain(); try { data.writeInterfaceToken(IpcVersionStability$$AidlServerImpl.DESCRIPTOR); delegate.transact(IpcVersionStability$$AidlServerImpl.TRANSACT_method, data, reply, 0); reply.readException(); return null; } finally { data.recycle(); reply.recycle(); } }
@Override protected boolean onTransact(int code, Parcel data, Parcel reply, int flags) throws RemoteException { switch(code) { case TRANSACT_methodWithBiCharArrayReturn: { data.enforceInterface(this.getInterfaceDescriptor()); final Void[] voidVararg = null; delegate.methodWithBiCharArrayReturn(voidVararg); reply.writeNoException(); return true; } } return super.onTransact(code, data, reply, flags); }
@Override public Void methodWithVoidReturn() throws RemoteException { Parcel data = Parcel.obtain(); Parcel reply = Parcel.obtain(); try { data.writeInterfaceToken(VoidTest$$AidlServerImpl.DESCRIPTOR); delegate.transact(VoidTest$$AidlServerImpl.TRANSACT_methodWithVoidReturn, data, reply, 0); reply.readException(); return null; } finally { data.recycle(); reply.recycle(); } }
@Override public Void run(TransactionContext context, P4<Integer, Integer, BigDecimal, Integer> params) throws SQLException { for (int i = 0; i < params._4(); i++) { context.execute(transfer, p(params._1(), params._2(), params._3())); } return null; }
@Override public void methodWithBiCharArrayReturn(Void... voidVararg) throws RemoteException { Parcel data = Parcel.obtain(); Parcel reply = Parcel.obtain(); try { data.writeInterfaceToken(VoidTest3$$AidlServerImpl.DESCRIPTOR); delegate.transact(VoidTest3$$AidlServerImpl.TRANSACT_methodWithBiCharArrayReturn, data, reply, 0); reply.readException(); } finally { data.recycle(); reply.recycle(); } }
@Override public void methodWithVoidParameter(Void ignored) throws RemoteException { Parcel data = Parcel.obtain(); Parcel reply = Parcel.obtain(); try { data.writeInterfaceToken(VoidTest2$$AidlServerImpl.DESCRIPTOR); delegate.transact(VoidTest2$$AidlServerImpl.TRANSACT_methodWithVoidParameter, data, reply, 0); reply.readException(); } finally { data.recycle(); reply.recycle(); } }
@Override protected boolean onTransact(int code, Parcel data, Parcel reply, int flags) throws RemoteException { switch(code) { case TRANSACT_methodWithVoidParameter: { data.enforceInterface(this.getInterfaceDescriptor()); final Void ignored = null; delegate.methodWithVoidParameter(ignored); reply.writeNoException(); return true; } } return super.onTransact(code, data, reply, flags); }
@Override protected File doInBackground(final Void... params) { final File groupDataFile = new File(GROUP_DATA_DIR+ File.separator + groupName + "_data.zip"); ensureDirExists(groupDataFile); final File unzipDir = new File(GROUP_DATA_DIR+ File.separator + groupName); ensureDirExists(unzipDir); try { final InputStream in = client.getGroupData(groupName, 6000); final OutputStream os = new FileOutputStream(groupDataFile); IOUtils.copy(in, os); IOUtils.closeQuietly(in); IOUtils.closeQuietly(os); unzipFile(groupDataFile, unzipDir); success = true; } catch (IOException e) { Log.e(TAG, "Map group data download/persistence or unzip failed! Falling back to cache (if such exists)."); } // If we don't have any maps inside the unzipped group directory, then something went wrong and we must signal // it. if(unzipDir.listFiles() == null || unzipDir.listFiles().length == 0 ) { success = false; } else { success = true; } return unzipDir; }
@SuppressWarnings("unchecked") @Test(timeout=10000) public void testCopyFromHostWithRetry() throws Exception { InMemoryMapOutput<Text, Text> immo = mock(InMemoryMapOutput.class); ss = mock(ShuffleSchedulerImpl.class); Fetcher<Text,Text> underTest = new FakeFetcher<Text,Text>(jobWithRetry, id, ss, mm, r, metrics, except, key, connection, true); String replyHash = SecureShuffleUtils.generateHash(encHash.getBytes(), key); when(connection.getResponseCode()).thenReturn(200); when(connection.getHeaderField(SecureShuffleUtils.HTTP_HEADER_REPLY_URL_HASH)) .thenReturn(replyHash); ShuffleHeader header = new ShuffleHeader(map1ID.toString(), 10, 10, 1); ByteArrayOutputStream bout = new ByteArrayOutputStream(); header.write(new DataOutputStream(bout)); ByteArrayInputStream in = new ByteArrayInputStream(bout.toByteArray()); when(connection.getInputStream()).thenReturn(in); when(connection.getHeaderField(ShuffleHeader.HTTP_HEADER_NAME)) .thenReturn(ShuffleHeader.DEFAULT_HTTP_HEADER_NAME); when(connection.getHeaderField(ShuffleHeader.HTTP_HEADER_VERSION)) .thenReturn(ShuffleHeader.DEFAULT_HTTP_HEADER_VERSION); when(mm.reserve(any(TaskAttemptID.class), anyLong(), anyInt())) .thenReturn(immo); final long retryTime = Time.monotonicNow(); doAnswer(new Answer<Void>() { public Void answer(InvocationOnMock ignore) throws IOException { // Emulate host down for 3 seconds. if ((Time.monotonicNow() - retryTime) <= 3000) { throw new java.lang.InternalError(); } return null; } }).when(immo).shuffle(any(MapHost.class), any(InputStream.class), anyLong(), anyLong(), any(ShuffleClientMetrics.class), any(Reporter.class)); underTest.copyFromHost(host); verify(ss, never()).copyFailed(any(TaskAttemptID.class),any(MapHost.class), anyBoolean(), anyBoolean()); }
@Test(timeout=10000) public void testInterruptInMemory() throws Exception { final int FETCHER = 2; InMemoryMapOutput<Text,Text> immo = spy(new InMemoryMapOutput<Text,Text>( job, id, mm, 100, null, true)); when(mm.reserve(any(TaskAttemptID.class), anyLong(), anyInt())) .thenReturn(immo); doNothing().when(mm).waitForResource(); when(ss.getHost()).thenReturn(host); String replyHash = SecureShuffleUtils.generateHash(encHash.getBytes(), key); when(connection.getResponseCode()).thenReturn(200); when(connection.getHeaderField(ShuffleHeader.HTTP_HEADER_NAME)) .thenReturn(ShuffleHeader.DEFAULT_HTTP_HEADER_NAME); when(connection.getHeaderField(ShuffleHeader.HTTP_HEADER_VERSION)) .thenReturn(ShuffleHeader.DEFAULT_HTTP_HEADER_VERSION); when(connection.getHeaderField(SecureShuffleUtils.HTTP_HEADER_REPLY_URL_HASH)) .thenReturn(replyHash); ShuffleHeader header = new ShuffleHeader(map1ID.toString(), 10, 10, 1); ByteArrayOutputStream bout = new ByteArrayOutputStream(); header.write(new DataOutputStream(bout)); final StuckInputStream in = new StuckInputStream(new ByteArrayInputStream(bout.toByteArray())); when(connection.getInputStream()).thenReturn(in); doAnswer(new Answer<Void>() { public Void answer(InvocationOnMock ignore) throws IOException { in.close(); return null; } }).when(connection).disconnect(); Fetcher<Text,Text> underTest = new FakeFetcher<Text,Text>(job, id, ss, mm, r, metrics, except, key, connection, FETCHER); underTest.start(); // wait for read in inputstream in.waitForFetcher(); underTest.shutDown(); underTest.join(); // rely on test timeout to kill if stuck assertTrue(in.wasClosedProperly()); verify(immo).abort(); }
@Test(timeout=10000) public void testInterruptOnDisk() throws Exception { final int FETCHER = 7; Path p = new Path("file:///tmp/foo"); Path pTmp = OnDiskMapOutput.getTempPath(p, FETCHER); FileSystem mFs = mock(FileSystem.class, RETURNS_DEEP_STUBS); MapOutputFile mof = mock(MapOutputFile.class); when(mof.getInputFileForWrite(any(TaskID.class), anyLong())).thenReturn(p); OnDiskMapOutput<Text,Text> odmo = spy(new OnDiskMapOutput<Text,Text>(map1ID, id, mm, 100L, job, mof, FETCHER, true, mFs, p)); when(mm.reserve(any(TaskAttemptID.class), anyLong(), anyInt())) .thenReturn(odmo); doNothing().when(mm).waitForResource(); when(ss.getHost()).thenReturn(host); String replyHash = SecureShuffleUtils.generateHash(encHash.getBytes(), key); when(connection.getResponseCode()).thenReturn(200); when(connection.getHeaderField( SecureShuffleUtils.HTTP_HEADER_REPLY_URL_HASH)).thenReturn(replyHash); ShuffleHeader header = new ShuffleHeader(map1ID.toString(), 10, 10, 1); ByteArrayOutputStream bout = new ByteArrayOutputStream(); header.write(new DataOutputStream(bout)); final StuckInputStream in = new StuckInputStream(new ByteArrayInputStream(bout.toByteArray())); when(connection.getInputStream()).thenReturn(in); when(connection.getHeaderField(ShuffleHeader.HTTP_HEADER_NAME)) .thenReturn(ShuffleHeader.DEFAULT_HTTP_HEADER_NAME); when(connection.getHeaderField(ShuffleHeader.HTTP_HEADER_VERSION)) .thenReturn(ShuffleHeader.DEFAULT_HTTP_HEADER_VERSION); doAnswer(new Answer<Void>() { public Void answer(InvocationOnMock ignore) throws IOException { in.close(); return null; } }).when(connection).disconnect(); Fetcher<Text,Text> underTest = new FakeFetcher<Text,Text>(job, id, ss, mm, r, metrics, except, key, connection, FETCHER); underTest.start(); // wait for read in inputstream in.waitForFetcher(); underTest.shutDown(); underTest.join(); // rely on test timeout to kill if stuck assertTrue(in.wasClosedProperly()); verify(mFs).create(eq(pTmp)); verify(mFs).delete(eq(pTmp), eq(false)); verify(odmo).abort(); }
@Test(timeout=10000) public void testInterruptInMemory() throws Exception { final int FETCHER = 2; IFileWrappedMapOutput<Text,Text> immo = spy(new InMemoryMapOutput<Text,Text>( job, id, mm, 100, null, true)); when(mm.reserve(any(TaskAttemptID.class), anyLong(), anyInt())) .thenReturn(immo); doNothing().when(mm).waitForResource(); when(ss.getHost()).thenReturn(host); String replyHash = SecureShuffleUtils.generateHash(encHash.getBytes(), key); when(connection.getResponseCode()).thenReturn(200); when(connection.getHeaderField(ShuffleHeader.HTTP_HEADER_NAME)) .thenReturn(ShuffleHeader.DEFAULT_HTTP_HEADER_NAME); when(connection.getHeaderField(ShuffleHeader.HTTP_HEADER_VERSION)) .thenReturn(ShuffleHeader.DEFAULT_HTTP_HEADER_VERSION); when(connection.getHeaderField(SecureShuffleUtils.HTTP_HEADER_REPLY_URL_HASH)) .thenReturn(replyHash); ShuffleHeader header = new ShuffleHeader(map1ID.toString(), 10, 10, 1); ByteArrayOutputStream bout = new ByteArrayOutputStream(); header.write(new DataOutputStream(bout)); final StuckInputStream in = new StuckInputStream(new ByteArrayInputStream(bout.toByteArray())); when(connection.getInputStream()).thenReturn(in); doAnswer(new Answer<Void>() { public Void answer(InvocationOnMock ignore) throws IOException { in.close(); return null; } }).when(connection).disconnect(); Fetcher<Text,Text> underTest = new FakeFetcher<Text,Text>(job, id, ss, mm, r, metrics, except, key, connection, FETCHER); underTest.start(); // wait for read in inputstream in.waitForFetcher(); underTest.shutDown(); underTest.join(); // rely on test timeout to kill if stuck assertTrue(in.wasClosedProperly()); verify(immo).abort(); }
@Test(timeout=10000) public void testInterruptOnDisk() throws Exception { final int FETCHER = 7; Path p = new Path("file:///tmp/foo"); Path pTmp = OnDiskMapOutput.getTempPath(p, FETCHER); FileSystem mFs = mock(FileSystem.class, RETURNS_DEEP_STUBS); IFileWrappedMapOutput<Text,Text> odmo = spy(new OnDiskMapOutput<Text,Text>(map1ID, mm, 100L, job, FETCHER, true, mFs, p)); when(mm.reserve(any(TaskAttemptID.class), anyLong(), anyInt())) .thenReturn(odmo); doNothing().when(mm).waitForResource(); when(ss.getHost()).thenReturn(host); String replyHash = SecureShuffleUtils.generateHash(encHash.getBytes(), key); when(connection.getResponseCode()).thenReturn(200); when(connection.getHeaderField( SecureShuffleUtils.HTTP_HEADER_REPLY_URL_HASH)).thenReturn(replyHash); ShuffleHeader header = new ShuffleHeader(map1ID.toString(), 10, 10, 1); ByteArrayOutputStream bout = new ByteArrayOutputStream(); header.write(new DataOutputStream(bout)); final StuckInputStream in = new StuckInputStream(new ByteArrayInputStream(bout.toByteArray())); when(connection.getInputStream()).thenReturn(in); when(connection.getHeaderField(ShuffleHeader.HTTP_HEADER_NAME)) .thenReturn(ShuffleHeader.DEFAULT_HTTP_HEADER_NAME); when(connection.getHeaderField(ShuffleHeader.HTTP_HEADER_VERSION)) .thenReturn(ShuffleHeader.DEFAULT_HTTP_HEADER_VERSION); doAnswer(new Answer<Void>() { public Void answer(InvocationOnMock ignore) throws IOException { in.close(); return null; } }).when(connection).disconnect(); Fetcher<Text,Text> underTest = new FakeFetcher<Text,Text>(job, id, ss, mm, r, metrics, except, key, connection, FETCHER); underTest.start(); // wait for read in inputstream in.waitForFetcher(); underTest.shutDown(); underTest.join(); // rely on test timeout to kill if stuck assertTrue(in.wasClosedProperly()); verify(mFs).create(eq(pTmp)); verify(mFs).delete(eq(pTmp), eq(false)); verify(odmo).abort(); }
@Override public Void run(TransactionContext context, Void aVoid) throws SQLException { context.execute(Statements.createAccountTable); return null; }
@Override public Void run(TransactionContext context, Void aVoid) throws SQLException { context.execute(Statements.dropAccountTable); return null; }
@Override public Void run(TransactionContext context, P3<Integer, Integer, BigDecimal> params) throws SQLException { context.execute(Statements.modifyBalance, p(params._1(), params._3().negate())); context.execute(Statements.modifyBalance, p(params._2(), params._3())); return null; }
@Override public void customBiomeRemoved(CustomBiome customBiome) { biomeNames[customBiome.getId()] = null; if ((! programmaticChange) && (dimension != null)) { ProgressDialog.executeTask(this, new ProgressTask<Void>() { @Override public String getName() { return "Removing custom biome " + customBiome.getName(); } @Override public Void execute(ProgressReceiver progressReceiver) throws OperationCancelled { dimension.armSavePoint(); int customBiomeId = customBiome.getId(); boolean biomesChanged = false; for (Tile tile: dimension.getTiles()) { if (tile.hasLayer(Biome.INSTANCE)) { tile.inhibitEvents(); try { boolean allCustomOrAuto = true; for (int x = 0; x < TILE_SIZE; x++) { for (int y = 0; y < TILE_SIZE; y++) { int layerValue = tile.getLayerValue(Biome.INSTANCE, x, y); if (layerValue == customBiomeId) { tile.setLayerValue(Biome.INSTANCE, x, y, 255); biomesChanged = true; } else if (layerValue != 255) { allCustomOrAuto = false; } } } if (allCustomOrAuto) { // This tile was completely filled with the // custom biome and/or automatic biome. // Since we're replacing it with automatic // biome, which is the default layer value, // we can delete the layer data to conserve // space tile.clearLayerData(Biome.INSTANCE); } } finally { tile.releaseEvents(); } } } if (biomesChanged) { dimension.armSavePoint(); } return null; } }, false); } }