Java 类java.lang.Void 实例源码

项目:aidl2    文件:IpcVersionStability$$AidlClientImpl.java   
@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();
  }
}
项目:aidl2    文件:VoidTest3$$AidlServerImpl.java   
@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);
}
项目:aidl2    文件:VoidTest$$AidlClientImpl.java   
@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();
    }
}
项目:djdbc    文件:Transactions.java   
@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;
}
项目:aidl2    文件:VoidTest3$$AidlClientImpl.java   
@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();
    }
}
项目:aidl2    文件:VoidTest2$$AidlClientImpl.java   
@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();
    }
}
项目:aidl2    文件:VoidTest2$$AidlServerImpl.java   
@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);
}
项目:invio    文件:CachedDownloadGroupDataTask.java   
@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;
}
项目:hadoop    文件:TestFetcher.java   
@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());
}
项目:hadoop    文件:TestFetcher.java   
@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();
}
项目:hadoop    文件:TestFetcher.java   
@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();
}
项目:aliyun-oss-hadoop-fs    文件:TestFetcher.java   
@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());
}
项目:aliyun-oss-hadoop-fs    文件:TestFetcher.java   
@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();
}
项目:aliyun-oss-hadoop-fs    文件:TestFetcher.java   
@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();
}
项目:big-c    文件:TestFetcher.java   
@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());
}
项目:big-c    文件:TestFetcher.java   
@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();
}
项目:big-c    文件:TestFetcher.java   
@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();
}
项目:djdbc    文件:Transactions.java   
@Override
public Void run(TransactionContext context, Void aVoid) throws SQLException {
  context.execute(Statements.createAccountTable);
  return null;
}
项目:djdbc    文件:Transactions.java   
@Override
public Void run(TransactionContext context, Void aVoid) throws SQLException {
  context.execute(Statements.dropAccountTable);
  return null;
}
项目:djdbc    文件:Transactions.java   
@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;
}
项目:hadoop-2.6.0-cdh5.4.3    文件:TestFetcher.java   
@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());
}
项目:hadoop-2.6.0-cdh5.4.3    文件:TestFetcher.java   
@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();
}
项目:hadoop-2.6.0-cdh5.4.3    文件:TestFetcher.java   
@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();
}
项目:hadoop-plus    文件:TestFetcher.java   
@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();
}
项目:hadoop-plus    文件:TestFetcher.java   
@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();
}
项目:FlexMap    文件:TestFetcher.java   
@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());
}
项目:FlexMap    文件:TestFetcher.java   
@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();
}
项目:FlexMap    文件:TestFetcher.java   
@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();
}
项目:hops    文件:TestFetcher.java   
@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());
}
项目:hops    文件:TestFetcher.java   
@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();
}
项目:hops    文件:TestFetcher.java   
@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();
}
项目:hadoop-TCP    文件:TestFetcher.java   
@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();
}
项目:hadoop-TCP    文件:TestFetcher.java   
@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();
}
项目:hardfs    文件:TestFetcher.java   
@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();
}
项目:hardfs    文件:TestFetcher.java   
@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();
}
项目:hadoop-on-lustre2    文件:TestFetcher.java   
@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();
}
项目:hadoop-on-lustre2    文件:TestFetcher.java   
@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();
}
项目:WorldPainter    文件:App.java   
@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);
    }
}