Java 类java.lang.InterruptedException 实例源码

项目:CaptivePortalAutologin    文件:CaptivePortalLoginActivity.java   
@Override
public void onDestroy() {
    super.onDestroy();

    if (mNetworkCallback != null) {
        mCm.unregisterNetworkCallback(mNetworkCallback);
        mNetworkCallback = null;
    }
    if (mLaunchBrowser) {
        // Give time for this network to become default. After 500ms just proceed.
        for (int i = 0; i < 5; i++) {
            // TODO: This misses when mNetwork underlies a VPN.
            if (mNetwork.equals(mCm.getActiveNetwork())) break;
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
            }
        }
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(mURL.toString())));
    }
}
项目:guava-mock    文件:TestingExecutorsTest.java   
public void testNoOpScheduledExecutorInvokeAll() throws ExecutionException, InterruptedException {
  ListeningScheduledExecutorService executor = TestingExecutors.noOpScheduledExecutor();
  taskDone = false;
  Callable<Boolean> task = new Callable<Boolean>() {
    @Override public Boolean call() {
      taskDone = true;
      return taskDone;
    }
  };
  List<Future<Boolean>> futureList = executor.invokeAll(
      ImmutableList.of(task), 10, TimeUnit.MILLISECONDS);
  Future<Boolean> future = futureList.get(0);
  assertFalse(taskDone);
  assertTrue(future.isDone());
  try {
    future.get();
    fail();
  } catch (CancellationException e) {
    // pass
  }
}
项目:RiskBots    文件:RunGame.java   
private void finish(IORobot bot1, IORobot bot2) throws InterruptedException
{
    bot1.finish();
    Thread.sleep(200);

    bot2.finish();
    Thread.sleep(200);

    Thread.sleep(200);

    // write everything
    // String outputFile = this.writeOutputFile(this.gameId, this.engine.winningPlayer());
    this.saveGame(bot1, bot2);

       System.exit(0);
}
项目:googles-monorepo-demo    文件:TestingExecutorsTest.java   
public void testNoOpScheduledExecutorInvokeAll() throws ExecutionException, InterruptedException {
  ListeningScheduledExecutorService executor = TestingExecutors.noOpScheduledExecutor();
  taskDone = false;
  Callable<Boolean> task = new Callable<Boolean>() {
    @Override public Boolean call() {
      taskDone = true;
      return taskDone;
    }
  };
  List<Future<Boolean>> futureList = executor.invokeAll(
      ImmutableList.of(task), 10, TimeUnit.MILLISECONDS);
  Future<Boolean> future = futureList.get(0);
  assertFalse(taskDone);
  assertTrue(future.isDone());
  try {
    future.get();
    fail();
  } catch (CancellationException e) {
    // pass
  }
}
项目:hadoopcryptoledger    文件:BitcoinFormatHadoopTest.java   
@Test
 public void readBitcoinRawBlockInputFormatGenesisBlock() throws IOException, InterruptedException {
   Configuration conf = new Configuration(defaultConf);
   ClassLoader classLoader = getClass().getClassLoader();
   String fileName="genesis.blk";
   String fileNameGenesis=classLoader.getResource("testdata/"+fileName).getFile();  
   Path file = new Path(fileNameGenesis);
   Job job = Job.getInstance(conf);
   FileInputFormat.setInputPaths(job, file);
   BitcoinRawBlockFileInputFormat format = new BitcoinRawBlockFileInputFormat();

   List<InputSplit> splits = format.getSplits(job);
   TaskAttemptContext context = new TaskAttemptContextImpl(conf, new TaskAttemptID());
   assertEquals( 1, splits.size(),"Only one split generated for genesis block");
    RecordReader<BytesWritable, BytesWritable> reader = format.createRecordReader(splits.get(0), context);
assertNotNull( reader,"Format returned  null RecordReader");
reader.initialize(splits.get(0),context);
BytesWritable genesisKey = new BytesWritable(); 
BytesWritable genesisBlock = new BytesWritable();
assertTrue( reader.nextKeyValue(),"Input Split for genesis block contains at least one block");
genesisKey=reader.getCurrentKey();
genesisBlock=reader.getCurrentValue();
assertEquals( 293, genesisBlock.getLength(),"Genesis Block must have size of 293");
    assertFalse( reader.nextKeyValue(),"No further blocks in genesis Block");
reader.close();
 }
项目:hadoopcryptoledger    文件:BitcoinFormatHadoopTest.java   
@Test
 public void readBitcoinRawBlockInputFormatBlockVersion1() throws IOException, InterruptedException {
   Configuration conf = new Configuration(defaultConf);
   ClassLoader classLoader = getClass().getClassLoader();
   String fileName="version1.blk";
   String fileNameBlock=classLoader.getResource("testdata/"+fileName).getFile();    
   Path file = new Path(fileNameBlock);
   Job job = Job.getInstance(conf);
   FileInputFormat.setInputPaths(job, file);
   BitcoinRawBlockFileInputFormat format = new BitcoinRawBlockFileInputFormat();
   List<InputSplit> splits = format.getSplits(job);
   TaskAttemptContext context = new TaskAttemptContextImpl(conf, new TaskAttemptID());
   assertEquals( 1, splits.size(),"Only one split generated for block version 1");
    RecordReader<BytesWritable, BytesWritable> reader = format.createRecordReader(splits.get(0), context);
assertNotNull( reader,"Format returned  null RecordReader");
reader.initialize(splits.get(0),context);
BytesWritable key = new BytesWritable();    
BytesWritable block = new BytesWritable();
assertTrue( reader.nextKeyValue(),"Input Split for block version contains at least one block");
block=reader.getCurrentValue();
assertEquals( 482, block.getLength(),"Random block version 1  must have size of 482 bytes");
    assertFalse( reader.nextKeyValue(),"No further blocks in block version 1");
reader.close();
 }
项目:hadoopcryptoledger    文件:BitcoinFormatHadoopTest.java   
@Test
 public void readBitcoinRawBlockInputFormatBlockVersion2() throws IOException, InterruptedException {
   Configuration conf = new Configuration(defaultConf);
   ClassLoader classLoader = getClass().getClassLoader();
   String fileName="version2.blk";
   String fileNameBlock=classLoader.getResource("testdata/"+fileName).getFile();    
   Path file = new Path(fileNameBlock);
Job job = Job.getInstance(conf);
   FileInputFormat.setInputPaths(job, file);
   BitcoinRawBlockFileInputFormat format = new BitcoinRawBlockFileInputFormat();
   List<InputSplit> splits = format.getSplits(job);
   TaskAttemptContext context = new TaskAttemptContextImpl(conf, new TaskAttemptID());
   assertEquals( 1, splits.size(),"Only one split generated for block version 2");
    RecordReader<BytesWritable, BytesWritable> reader = format.createRecordReader(splits.get(0), context);
assertNotNull( reader,"Format returned  null RecordReader");
reader.initialize(splits.get(0),context);
BytesWritable key = new BytesWritable();    
BytesWritable block = new BytesWritable();
assertTrue( reader.nextKeyValue(),"Input Split for block version contains at least one block");
block=reader.getCurrentValue();
assertEquals( 191198, block.getLength(),"Random block version 2  must have size of 191.198 bytes");
    assertFalse( reader.nextKeyValue(),"No further blocks in block version 2");
reader.close();
 }
项目:hadoopcryptoledger    文件:BitcoinFormatHadoopTest.java   
@Test
 public void readBitcoinRawBlockInputFormatBlockVersion3() throws IOException, InterruptedException {
   Configuration conf = new Configuration(defaultConf);
   ClassLoader classLoader = getClass().getClassLoader();
   String fileName="version3.blk";
   String fileNameBlock=classLoader.getResource("testdata/"+fileName).getFile();    
   Path file = new Path(fileNameBlock);
Job job = Job.getInstance(conf);
   FileInputFormat.setInputPaths(job, file);
   BitcoinRawBlockFileInputFormat format = new BitcoinRawBlockFileInputFormat();
   List<InputSplit> splits = format.getSplits(job);
   TaskAttemptContext context = new TaskAttemptContextImpl(conf, new TaskAttemptID());
   assertEquals( 1, splits.size(),"Only one split generated for block version 3");
    RecordReader<BytesWritable, BytesWritable> reader = format.createRecordReader(splits.get(0), context);
assertNotNull( reader,"Format returned  null RecordReader");
reader.initialize(splits.get(0),context);
BytesWritable key = new BytesWritable();    
BytesWritable block = new BytesWritable();
assertTrue( reader.nextKeyValue(),"Input Split for block version contains at least one block");
block=reader.getCurrentValue();
assertEquals( 932199, block.getLength(),"Random block version 3 must have size of 932.199 bytes");
    assertFalse( reader.nextKeyValue(),"No further blocks in block version 3");
reader.close();
 }
项目:hadoopcryptoledger    文件:BitcoinFormatHadoopTest.java   
@Test
 public void readBitcoinRawBlockInputFormatBlockVersion4() throws IOException, InterruptedException {
   Configuration conf = new Configuration(defaultConf);
   ClassLoader classLoader = getClass().getClassLoader();
   String fileName="version4.blk";
   String fileNameBlock=classLoader.getResource("testdata/"+fileName).getFile();    
   Path file = new Path(fileNameBlock);
    Job job = Job.getInstance(conf);
   FileInputFormat.setInputPaths(job, file);
   BitcoinRawBlockFileInputFormat format = new BitcoinRawBlockFileInputFormat();
    List<InputSplit> splits = format.getSplits(job);
   TaskAttemptContext context = new TaskAttemptContextImpl(conf, new TaskAttemptID());
   assertEquals( 1, splits.size(),"Only one split generated for block version 4");
    RecordReader<BytesWritable, BytesWritable> reader = format.createRecordReader(splits.get(0), context);
assertNotNull( reader,"Format returned  null RecordReader");
reader.initialize(splits.get(0),context);
BytesWritable key = new BytesWritable();    
BytesWritable block = new BytesWritable();
assertTrue( reader.nextKeyValue(),"Input Split for block version contains at least one block");
block=reader.getCurrentValue();
assertEquals( 998039, block.getLength(),"Random block version 4 must have a size of 998.039 bytes");
    assertFalse( reader.nextKeyValue(),"No further blocks in block version 4");
reader.close();
 }
项目:hadoopcryptoledger    文件:BitcoinFormatHadoopTest.java   
@Test
 public void readBitcoinRawBlockInputFormatReqSeekBlockVersion1() throws IOException, InterruptedException {
   Configuration conf = new Configuration(defaultConf);
   ClassLoader classLoader = getClass().getClassLoader();
   String fileName="reqseekversion1.blk";
   String fileNameBlock=classLoader.getResource("testdata/"+fileName).getFile();    
   Path file = new Path(fileNameBlock);
        Job job = Job.getInstance(conf);
   FileInputFormat.setInputPaths(job, file);
   BitcoinRawBlockFileInputFormat format = new BitcoinRawBlockFileInputFormat();
   List<InputSplit> splits = format.getSplits(job);
   TaskAttemptContext context = new TaskAttemptContextImpl(conf, new TaskAttemptID());
   assertEquals( 1, splits.size(),"Only one split generated for block requiring seek version 1");
    RecordReader<BytesWritable, BytesWritable> reader = format.createRecordReader(splits.get(0), context);
assertNotNull( reader,"Format returned  null RecordReader");
reader.initialize(splits.get(0),context);
BytesWritable key = new BytesWritable();    
BytesWritable block = new BytesWritable();
assertTrue( reader.nextKeyValue(),"Input Split for block version contains at least one block");
block=reader.getCurrentValue();
assertEquals( 482, block.getLength(),"Random block requiring seek version 1 must have a size of 482 bytes");
    assertFalse( reader.nextKeyValue(),"No further blocks in block requiring seek version 1");
reader.close();
 }
项目:hadoopcryptoledger    文件:BitcoinFormatHadoopTest.java   
@Test
 public void readBitcoinBlockInputFormatGenesisBlock() throws IOException, InterruptedException {
   Configuration conf = new Configuration(defaultConf);
   ClassLoader classLoader = getClass().getClassLoader();
   String fileName="genesis.blk";
   String fileNameGenesis=classLoader.getResource("testdata/"+fileName).getFile();  
   Path file = new Path(fileNameGenesis);
   Job job = Job.getInstance(conf);
   FileInputFormat.setInputPaths(job, file);
   BitcoinBlockFileInputFormat format = new BitcoinBlockFileInputFormat();
   List<InputSplit> splits = format.getSplits(job);
   TaskAttemptContext context = new TaskAttemptContextImpl(conf, new TaskAttemptID());
   assertEquals( 1, splits.size(),"Only one split generated for genesis block");
    RecordReader<BytesWritable, BitcoinBlock> reader = format.createRecordReader(splits.get(0), context);
assertNotNull( reader,"Format returned  null RecordReader");
reader.initialize(splits.get(0),context);
BytesWritable genesisKey = new BytesWritable(); 
BitcoinBlock genesisBlock = new BitcoinBlock();
assertTrue( reader.nextKeyValue(),"Input Split for genesis block contains at least one block");
genesisBlock=reader.getCurrentValue();
assertEquals( 1, genesisBlock.getTransactions().size(),"Genesis Block must contain exactly one transaction");
    assertFalse( reader.nextKeyValue(),"No further blocks in genesis Block");
reader.close();
 }
项目:hadoopcryptoledger    文件:BitcoinFormatHadoopTest.java   
@Test
 public void readBitcoinBlockInputFormatBlockVersion1() throws IOException, InterruptedException {
   Configuration conf = new Configuration(defaultConf);
   ClassLoader classLoader = getClass().getClassLoader();
   String fileName="version1.blk";
   String fileNameBlock=classLoader.getResource("testdata/"+fileName).getFile();    
   Path file = new Path(fileNameBlock);
   Job job = Job.getInstance(conf);
   FileInputFormat.setInputPaths(job, file);
   BitcoinBlockFileInputFormat format = new BitcoinBlockFileInputFormat();
   List<InputSplit> splits = format.getSplits(job);
   TaskAttemptContext context = new TaskAttemptContextImpl(conf, new TaskAttemptID());
   assertEquals( 1, splits.size(),"Only one split generated for block version 1");
    RecordReader<BytesWritable, BitcoinBlock> reader = format.createRecordReader(splits.get(0), context);
assertNotNull( reader,"Format returned  null RecordReader");
reader.initialize(splits.get(0),context);
BytesWritable key = new BytesWritable();    
BitcoinBlock block = new BitcoinBlock();
assertTrue( reader.nextKeyValue(),"Input Split for block version contains at least one block");
block=reader.getCurrentValue();
assertEquals( 2, block.getTransactions().size(),"Random block version 1  must contain exactly two transactions");
    assertFalse( reader.nextKeyValue(),"No further blocks in block version 1");
reader.close(); 
 }
项目:hadoopcryptoledger    文件:BitcoinFormatHadoopTest.java   
@Test
 public void readBitcoinBlockInputFormatBlockVersion2() throws IOException, InterruptedException {
   Configuration conf = new Configuration(defaultConf);
   ClassLoader classLoader = getClass().getClassLoader();
   String fileName="version2.blk";
   String fileNameBlock=classLoader.getResource("testdata/"+fileName).getFile();    
   Path file = new Path(fileNameBlock);
   Job job = Job.getInstance(conf);
   FileInputFormat.setInputPaths(job, file);
   BitcoinBlockFileInputFormat format = new BitcoinBlockFileInputFormat();
   List<InputSplit> splits = format.getSplits(job);
   TaskAttemptContext context = new TaskAttemptContextImpl(conf, new TaskAttemptID());
   assertEquals( 1, splits.size(),"Only one split generated for block version 2");
    RecordReader<BytesWritable, BitcoinBlock> reader = format.createRecordReader(splits.get(0), context);
assertNotNull( reader,"Format returned  null RecordReader");
reader.initialize(splits.get(0),context);
BytesWritable key = new BytesWritable();    
BitcoinBlock block = new BitcoinBlock();
assertTrue( reader.nextKeyValue(),"Input Split for block version contains at least one block");
block=reader.getCurrentValue();
assertEquals( 343, block.getTransactions().size(),"Random block version 2  must contain exactly 343 transactions");
    assertFalse( reader.nextKeyValue(),"No further blocks in block version 2");
reader.close();
 }
项目:hadoopcryptoledger    文件:BitcoinFormatHadoopTest.java   
@Test
 public void readBitcoinBlockInputFormatBlockVersion3() throws IOException, InterruptedException {
   Configuration conf = new Configuration(defaultConf);
   ClassLoader classLoader = getClass().getClassLoader();
   String fileName="version3.blk";
   String fileNameBlock=classLoader.getResource("testdata/"+fileName).getFile();    
   Path file = new Path(fileNameBlock);
   Job job = Job.getInstance(conf);
   FileInputFormat.setInputPaths(job, file);
   BitcoinBlockFileInputFormat format = new BitcoinBlockFileInputFormat();
   List<InputSplit> splits = format.getSplits(job);
   TaskAttemptContext context = new TaskAttemptContextImpl(conf, new TaskAttemptID());
   assertEquals( 1,splits.size(),"Only one split generated for block version 3");
    RecordReader<BytesWritable, BitcoinBlock> reader = format.createRecordReader(splits.get(0), context);
assertNotNull( reader,"Format returned  null RecordReader");
reader.initialize(splits.get(0),context);
BytesWritable key = new BytesWritable();    
BitcoinBlock block = new BitcoinBlock();
assertTrue( reader.nextKeyValue(),"Input Split for block version contains at least one block");
block=reader.getCurrentValue();
assertEquals( 1645, block.getTransactions().size(),"Random block version 3 must contain exactly 1645 transactions");
    assertFalse( reader.nextKeyValue(),"No further blocks in block version 3");
reader.close();
 }
项目:hadoopcryptoledger    文件:BitcoinFormatHadoopTest.java   
@Test
 public void readBitcoinBlockInputFormatBlockVersion4() throws IOException, InterruptedException {
   Configuration conf = new Configuration(defaultConf);
   ClassLoader classLoader = getClass().getClassLoader();
   String fileName="version4.blk";
   String fileNameBlock=classLoader.getResource("testdata/"+fileName).getFile();    
   Path file = new Path(fileNameBlock);
   Job job = Job.getInstance(conf);
   FileInputFormat.setInputPaths(job, file);
   BitcoinBlockFileInputFormat format = new BitcoinBlockFileInputFormat();
  List<InputSplit> splits = format.getSplits(job);
   TaskAttemptContext context = new TaskAttemptContextImpl(conf, new TaskAttemptID());
   assertEquals( 1, splits.size(),"Only one split generated for block version 4");
    RecordReader<BytesWritable, BitcoinBlock> reader = format.createRecordReader(splits.get(0), context);
assertNotNull( reader,"Format returned  null RecordReader");
reader.initialize(splits.get(0),context);
BytesWritable key = new BytesWritable();    
BitcoinBlock block = new BitcoinBlock();
assertTrue( reader.nextKeyValue(),"Input Split for block version contains at least one block");
block=reader.getCurrentValue();
assertEquals( 936, block.getTransactions().size(),"Random block version 4 must contain exactly 936 transactions");
    assertFalse( reader.nextKeyValue(),"No further blocks in block version 4");
reader.close();
 }
项目:hadoopcryptoledger    文件:BitcoinFormatHadoopTest.java   
@Test
 public void readBitcoinBlockInputFormatReqSeekBlockVersion1() throws IOException, InterruptedException {
   Configuration conf = new Configuration(defaultConf);
   ClassLoader classLoader = getClass().getClassLoader();
   String fileName="reqseekversion1.blk";
   String fileNameBlock=classLoader.getResource("testdata/"+fileName).getFile();    
   Path file = new Path(fileNameBlock);
   Job job = Job.getInstance(conf);
   FileInputFormat.setInputPaths(job, file);
   BitcoinBlockFileInputFormat format = new BitcoinBlockFileInputFormat();
  List<InputSplit> splits = format.getSplits(job);
   TaskAttemptContext context = new TaskAttemptContextImpl(conf, new TaskAttemptID());
   assertEquals( 1, splits.size(),"Only one split generated for block requiring seek version 1");
    RecordReader<BytesWritable, BitcoinBlock> reader = format.createRecordReader(splits.get(0), context);
assertNotNull( reader,"Format returned  null RecordReader");
reader.initialize(splits.get(0),context);
BytesWritable key = new BytesWritable();    
BitcoinBlock block = new BitcoinBlock();
assertTrue( reader.nextKeyValue(),"Input Split for block version contains at least one block");
block=reader.getCurrentValue();
assertEquals( 2, block.getTransactions().size(),"Random block requiring seek version 1 must contain exactly two transactions");
    assertFalse( reader.nextKeyValue(),"No further blocks in block requiring seek version 1");
reader.close(); 
 }
项目:hadoopcryptoledger    文件:BitcoinFormatHadoopTest.java   
@Test
 public void readBitcoinTransactionInputFormatGenesisBlock() throws IOException, InterruptedException {
   Configuration conf = new Configuration(defaultConf);
   ClassLoader classLoader = getClass().getClassLoader();
   String fileName="genesis.blk";
   String fileNameBlock=classLoader.getResource("testdata/"+fileName).getFile();    
   Path file = new Path(fileNameBlock);
   Job job = Job.getInstance(conf);
   FileInputFormat.setInputPaths(job, file);
   BitcoinTransactionFileInputFormat format = new BitcoinTransactionFileInputFormat();
 List<InputSplit> splits = format.getSplits(job);
   TaskAttemptContext context = new TaskAttemptContextImpl(conf, new TaskAttemptID());
   assertEquals( 1, splits.size(),"Only one split generated for genesis block");
    RecordReader<BytesWritable, BitcoinTransaction> reader = format.createRecordReader(splits.get(0), context);
assertNotNull( reader,"Format returned  null RecordReader");
reader.initialize(splits.get(0),context);
int transactCount=0;
while (reader.nextKeyValue()) {
    transactCount++;
}
assertEquals( 1, transactCount,"Genesis Block  must contain exactly one transactions");
reader.close();
 }
项目:hadoopcryptoledger    文件:BitcoinFormatHadoopTest.java   
@Test
 public void readBitcoinTransactionInputFormatBlockVersion1() throws IOException, InterruptedException {
   Configuration conf = new Configuration(defaultConf);
   ClassLoader classLoader = getClass().getClassLoader();
   String fileName="version1.blk";
   String fileNameBlock=classLoader.getResource("testdata/"+fileName).getFile();    
   Path file = new Path(fileNameBlock);
   Job job = Job.getInstance(conf);
   FileInputFormat.setInputPaths(job, file);
   BitcoinTransactionFileInputFormat format = new BitcoinTransactionFileInputFormat();
    List<InputSplit> splits = format.getSplits(job);
   TaskAttemptContext context = new TaskAttemptContextImpl(conf, new TaskAttemptID());
   assertEquals( 1, splits.size(),"Only one split generated for block version 1");
    RecordReader<BytesWritable, BitcoinTransaction> reader = format.createRecordReader(splits.get(0),context);
assertNotNull( reader,"Format returned  null RecordReader");
reader.initialize(splits.get(0),context);
int transactCount=0;
while (reader.nextKeyValue()) {
    transactCount++;
}
assertEquals( 2, transactCount,"Block version 1 must contain exactly two transactions");
reader.close();
 }
项目:hadoopcryptoledger    文件:BitcoinFormatHadoopTest.java   
@Test
 public void readBitcoinTransactionInputFormatBlockVersion2() throws IOException, InterruptedException {
   Configuration conf = new Configuration(defaultConf);
   ClassLoader classLoader = getClass().getClassLoader();
   String fileName="version2.blk";
   String fileNameBlock=classLoader.getResource("testdata/"+fileName).getFile();    
   Path file = new Path(fileNameBlock);
   Job job = Job.getInstance(conf);
   FileInputFormat.setInputPaths(job, file);
   BitcoinTransactionFileInputFormat format = new BitcoinTransactionFileInputFormat();
    List<InputSplit> splits = format.getSplits(job);
   TaskAttemptContext context = new TaskAttemptContextImpl(conf, new TaskAttemptID());
   assertEquals( 1, splits.size(),"Only one split generated for block version 2");
    RecordReader<BytesWritable, BitcoinTransaction> reader = format.createRecordReader(splits.get(0), context);
assertNotNull( reader,"Format returned  null RecordReader");
reader.initialize(splits.get(0),context);
int transactCount=0;
while (reader.nextKeyValue()) {
    transactCount++;
}
assertEquals( 343, transactCount,"Block version 2 must contain exactly 343 transactions");
reader.close();
 }
项目:hadoopcryptoledger    文件:BitcoinFormatHadoopTest.java   
@Test
 public void readBitcoinTransactionInputFormatBlockVersion3() throws IOException, InterruptedException {
   Configuration conf = new Configuration(defaultConf);
   ClassLoader classLoader = getClass().getClassLoader();
   String fileName="version3.blk";
   String fileNameBlock=classLoader.getResource("testdata/"+fileName).getFile();    
   Path file = new Path(fileNameBlock);
   Job job = Job.getInstance(conf);
   FileInputFormat.setInputPaths(job, file);
   BitcoinTransactionFileInputFormat format = new BitcoinTransactionFileInputFormat();
    List<InputSplit> splits = format.getSplits(job);
   TaskAttemptContext context = new TaskAttemptContextImpl(conf, new TaskAttemptID());
   assertEquals( 1, splits.size(),"Only one split generated for block version 3");
    RecordReader<BytesWritable, BitcoinTransaction> reader = format.createRecordReader(splits.get(0), context);
assertNotNull( reader,"Format returned  null RecordReader");
reader.initialize(splits.get(0),context);
int transactCount=0;
while (reader.nextKeyValue()) {
    transactCount++;
}
assertEquals( 1645, transactCount,"Block version 3 must contain exactly 1645 transactions");
reader.close();
 }
项目:hadoopcryptoledger    文件:BitcoinFormatHadoopTest.java   
@Test
 public void readBitcoinTransactionInputFormatBlockVersion4() throws IOException, InterruptedException {
   Configuration conf = new Configuration(defaultConf);
   ClassLoader classLoader = getClass().getClassLoader();
   String fileName="version4.blk";
   String fileNameBlock=classLoader.getResource("testdata/"+fileName).getFile();    
   Path file = new Path(fileNameBlock);
   Job job = Job.getInstance(conf);
   FileInputFormat.setInputPaths(job, file);
   BitcoinTransactionFileInputFormat format = new BitcoinTransactionFileInputFormat();
    List<InputSplit> splits = format.getSplits(job);
   TaskAttemptContext context = new TaskAttemptContextImpl(conf, new TaskAttemptID());
   assertEquals( 1, splits.size(),"Only one split generated for block version 4");
    RecordReader<BytesWritable, BitcoinTransaction> reader = format.createRecordReader(splits.get(0), context);
assertNotNull( reader,"Format returned  null RecordReader");
reader.initialize(splits.get(0),context);
int transactCount=0;
while (reader.nextKeyValue()) {
    transactCount++;
}
assertEquals( 936, transactCount,"Block version 4 must contain exactly 936 transactions");
reader.close();
 }
项目:hadoopcryptoledger    文件:BitcoinFormatHadoopTest.java   
@Test
 public void readBitcoinTransactionInputFormatBlockVersion1ReqSeek() throws IOException, InterruptedException {
  Configuration conf = new Configuration(defaultConf);
   ClassLoader classLoader = getClass().getClassLoader();
   String fileName="reqseekversion1.blk";
   String fileNameBlock=classLoader.getResource("testdata/"+fileName).getFile();    
   Path file = new Path(fileNameBlock);
   Job job = Job.getInstance(conf);
   FileInputFormat.setInputPaths(job, file);
   BitcoinTransactionFileInputFormat format = new BitcoinTransactionFileInputFormat();
   List<InputSplit> splits = format.getSplits(job);
   TaskAttemptContext context = new TaskAttemptContextImpl(conf, new TaskAttemptID());
   assertEquals( 1, splits.size(),"Only one split generated for block version 1 requiring seek");
    RecordReader<BytesWritable, BitcoinTransaction> reader = format.createRecordReader(splits.get(0), context);
assertNotNull( reader,"Format returned  null RecordReader");
reader.initialize(splits.get(0),context);
int transactCount=0;
while (reader.nextKeyValue()) {
    transactCount++;
}
assertEquals( 2, transactCount,"Block version 1 requiring seek must contain exactly two transactions");
reader.close();
 }
项目:hadoopcryptoledger    文件:BitcoinFormatHadoopTest.java   
@Test
 public void readBitcoinTransactionInputFormatMultiBlock() throws IOException, InterruptedException {
  Configuration conf = new Configuration(defaultConf);
   ClassLoader classLoader = getClass().getClassLoader();
   String fileName="multiblock.blk";
   String fileNameBlock=classLoader.getResource("testdata/"+fileName).getFile();    
   Path file = new Path(fileNameBlock);
   Job job = Job.getInstance(conf);
   FileInputFormat.setInputPaths(job, file);
   BitcoinTransactionFileInputFormat format = new BitcoinTransactionFileInputFormat();
   List<InputSplit> splits = format.getSplits(job);
   TaskAttemptContext context = new TaskAttemptContextImpl(conf, new TaskAttemptID());
   assertEquals( 1, splits.size(),"Only one split generated for multi block");
    RecordReader<BytesWritable, BitcoinTransaction> reader = format.createRecordReader(splits.get(0), context);
assertNotNull( reader,"Format returned  null RecordReader");
reader.initialize(splits.get(0),context);
int transactCount=0;
while (reader.nextKeyValue()) {
    transactCount++;
}
assertEquals( 346, transactCount,"Multiblock must contain exactly 1+2+343=346 transactions");
reader.close();
 }
项目:hadoopcryptoledger    文件:BitcoinFormatHadoopTest.java   
@Test
 public void readBitcoinRawBlockInputFormatGzipCompressed() throws IOException, InterruptedException {
  Configuration conf = new Configuration(defaultConf);
   Job job = Job.getInstance(conf);
   CompressionCodec gzip = new GzipCodec();
   ReflectionUtils.setConf(gzip, conf);
   ClassLoader classLoader = getClass().getClassLoader();
   String fileName="version4comp.blk.gz";
   String fileNameBlock=classLoader.getResource("testdata/"+fileName).getFile();    
   Path file = new Path(fileNameBlock);
   FileInputFormat.setInputPaths(job, file);
   BitcoinRawBlockFileInputFormat format = new BitcoinRawBlockFileInputFormat();
   List<InputSplit> splits = format.getSplits(job);
   TaskAttemptContext context = new TaskAttemptContextImpl(conf, new TaskAttemptID());
   assertEquals( 1, splits.size(),"Only one split generated for compressed block");
    RecordReader<BytesWritable, BytesWritable> reader = format.createRecordReader(splits.get(0), context);
assertNotNull( reader,"Format returned  null RecordReader");
reader.initialize(splits.get(0),context);
BytesWritable key = new BytesWritable();    
BytesWritable block = new BytesWritable();
assertTrue( reader.nextKeyValue(),"Input Split for block version contains at least one block");
block=reader.getCurrentValue();
assertEquals( 998039, block.getLength(),"Compressed block must have a size of 998.039 bytes");
    assertFalse( reader.nextKeyValue(),"No further blocks in compressed block");
reader.close();
 }
项目:hadoopcryptoledger    文件:BitcoinFormatHadoopTest.java   
@Test
 public void readBitcoinTransactionInputFormatGzipCompressed() throws IOException, InterruptedException{
Configuration conf = new Configuration(defaultConf);
   Job job = Job.getInstance(conf);
   CompressionCodec gzip = new GzipCodec();
   ReflectionUtils.setConf(gzip, conf);
   ClassLoader classLoader = getClass().getClassLoader();
   String fileName="version4comp.blk.gz";
   String fileNameBlock=classLoader.getResource("testdata/"+fileName).getFile();    
   Path file = new Path(fileNameBlock);
   FileInputFormat.setInputPaths(job, file);
   BitcoinTransactionFileInputFormat format = new BitcoinTransactionFileInputFormat();
   List<InputSplit> splits = format.getSplits(job);
   TaskAttemptContext context = new TaskAttemptContextImpl(conf, new TaskAttemptID());
   assertEquals( 1, splits.size(),"Only one split generated for compressed block");
    RecordReader<BytesWritable, BitcoinTransaction> reader = format.createRecordReader(splits.get(0), context);
assertNotNull( reader,"Format returned  null RecordReader");
reader.initialize(splits.get(0),context);
int transactCount=0;
while (reader.nextKeyValue()) {
    transactCount++;
}
    assertEquals( 936, transactCount,"Comrpessed block must have at least 936 transactions");
reader.close();
 }
项目:hadoopcryptoledger    文件:BitcoinFormatHadoopTest.java   
@Test
 public void readBitcoinRawBlockInputFormatBzip2Compressed() throws IOException, InterruptedException {
Configuration conf = new Configuration(defaultConf);
   Job job = Job.getInstance(conf);
   CompressionCodec bzip2 = new BZip2Codec();
   ReflectionUtils.setConf(bzip2, conf);
   ClassLoader classLoader = getClass().getClassLoader();
   String fileName="version4comp.blk.bz2";
   String fileNameBlock=classLoader.getResource("testdata/"+fileName).getFile();    
   Path file = new Path(fileNameBlock);
   FileInputFormat.setInputPaths(job, file);
   BitcoinRawBlockFileInputFormat format = new BitcoinRawBlockFileInputFormat();
   List<InputSplit> splits = format.getSplits(job);
   TaskAttemptContext context = new TaskAttemptContextImpl(conf, new TaskAttemptID());
   assertEquals( 1, splits.size(),"Only one split generated for compressed block");
    RecordReader<BytesWritable, BytesWritable> reader = format.createRecordReader(splits.get(0), context);
assertNotNull( reader,"Format returned  null RecordReader");
reader.initialize(splits.get(0),context);
BytesWritable key = new BytesWritable();    
BytesWritable block = new BytesWritable();
assertTrue( reader.nextKeyValue(),"Input Split for block version contains at least one block");
block=reader.getCurrentValue();
assertEquals( 998039, block.getLength(),"Compressed block must have a size of 998.039 bytes");
    assertFalse( reader.nextKeyValue(),"No further blocks in compressed block");
reader.close();
 }
项目:hadoopcryptoledger    文件:BitcoinFormatHadoopTest.java   
@Test
 public void readBitcoinTransactionInputFormatBzip2Compressed() throws IOException, InterruptedException {
Configuration conf = new Configuration(defaultConf);
   Job job = Job.getInstance(conf);
   CompressionCodec bzip2 = new BZip2Codec();
   ReflectionUtils.setConf(bzip2, conf);
   ClassLoader classLoader = getClass().getClassLoader();
   String fileName="version4comp.blk.bz2";
   String fileNameBlock=classLoader.getResource("testdata/"+fileName).getFile();    
   Path file = new Path(fileNameBlock);
   FileInputFormat.setInputPaths(job, file);
   BitcoinTransactionFileInputFormat format = new BitcoinTransactionFileInputFormat();
   List<InputSplit> splits = format.getSplits(job);
   TaskAttemptContext context = new TaskAttemptContextImpl(conf, new TaskAttemptID());
   assertEquals( 1, splits.size(),"Only one split generated for compressed block");
    RecordReader<BytesWritable, BitcoinTransaction> reader = format.createRecordReader(splits.get(0), context);
assertNotNull( reader,"Format returned  null RecordReader");
reader.initialize(splits.get(0),context);
int transactCount=0;
while (reader.nextKeyValue()) {
    transactCount++;
}
    assertEquals( 936, transactCount,"Compressed block must have at least 936 transactions");
reader.close();
 }
项目:ca-iris    文件:OSUtils.java   
/**
 * Spawn an OS subprocess.  Follows the Oracle-recommended method of
 * using ProcessBuilder rather than Runtime.exec(), and includes some
 * safeguards to prevent blocked and stale processes.  A thread is
 * created that will perform the spawn, consume its output and error
 * streams (to prevent blocking due to full buffers), then clean up.
 *
 * @param cmd The cmd/arg list for execution
 */
static public void spawnProcess(final List<String> cmd) {
    if (cmd == null)
        return;
    Thread t = new Thread() {
        public void run() {
            Process proc = null;
            proc = startProcess(cmd, true);
            if (proc != null) {
                consumeProcessOutput(proc);
                try {
                    proc.waitFor();
                }
                catch (InterruptedException e) {
                    // ignore (we terminate anyway)
                }
                destroyProcess(proc);
            }
            Thread.currentThread().interrupt();
        }
    };
    t.setDaemon(true);
    t.start();
}
项目:guava-libraries    文件:TestingExecutorsTest.java   
public void testNoOpScheduledExecutorInvokeAll() throws ExecutionException, InterruptedException {
  ListeningScheduledExecutorService executor = TestingExecutors.noOpScheduledExecutor();
  taskDone = false;
  Callable<Boolean> task = new Callable<Boolean>() {
    @Override public Boolean call() {
      taskDone = true;
      return taskDone;
    }
  };
  List<Future<Boolean>> futureList = executor.invokeAll(
      ImmutableList.of(task), 10, TimeUnit.MILLISECONDS);
  Future<Boolean> future = futureList.get(0);
  assertFalse(taskDone);
  assertTrue(future.isDone());
  try {
    future.get();
    fail();
  } catch (CancellationException e) {
    // pass
  }
}
项目:Java-by-Notepad    文件:HTML2MD.java   
public static void main(String... args) throws IOException, InterruptedException {
    if (args.length == 0) {
        System.err.println(usage);
        System.exit(1);
    }
    Path path = FileSystems.getDefault().getPath(".", args[0]);
    byte[] bytes = Files.readAllBytes(path);
    String string = new String(bytes, StandardCharsets.UTF_8);

    string = string.replaceAll("\n", "\1");
    string = string.replaceAll("<html>\1*(.*)</html>", "$1");
    string = string.replaceAll("\\s*<head>(.*)</head>", "");
    string = string.replaceAll("\\s*<body>\1*(.*)</body>", "$1");
    string = string.replaceAll("\\s*<h1>(.*?)</h1>", "\1\1\1\1\1# $1");
    string = replaceHeadings(string);
    string = string.replaceAll("[\1\\s]*<p>(.*?)</p>", "\1\1$1");
    string = replaceBullets(string, "ul", "*");
    string = replaceBullets(string, "ol", "#.");
    string = string.replaceAll("\1", "\n");

    System.out.println(string);
}
项目:pluotsorbet    文件:constructor.java   
/**
 * Runs the test using the specified harness.
 *
 * @param harness  the test harness (<code>null</code> not permitted).
 */
public void test(TestHarness harness)
{
    InterruptedException object1 = new InterruptedException();
    harness.check(object1 != null);
    harness.check(object1.toString(), "java.lang.InterruptedException");

    InterruptedException object2 = new InterruptedException("nothing happens");
    harness.check(object2 != null);
    harness.check(object2.toString(), "java.lang.InterruptedException: nothing happens");

    InterruptedException object3 = new InterruptedException(null);
    harness.check(object3 != null);
    harness.check(object3.toString(), "java.lang.InterruptedException");

}
项目:testrail-jenkins-plugin    文件:TestRailClient.java   
private TestRailResponse httpGet(String path) throws IOException {
    TestRailResponse response;

    do {
        response = httpGetInt(path);
        if (response.getStatus() == 429) {
            try {
                Thread.sleep(60000);
            } catch (InterruptedException e) {
                log(e.toString());
            }
        }
   } while (response.getStatus() == 429);

   return response;
}
项目:testrail-jenkins-plugin    文件:TestRailClient.java   
private TestRailResponse httpPost(String path, String payload)
    throws UnsupportedEncodingException, IOException, HTTPException {
    TestRailResponse response;

    do {
        response = httpPostInt(path, payload);
        if (response.getStatus() == 429) {
            try {
                Thread.sleep(60000);
            } catch (InterruptedException e) {
                log(e.toString());
            }
        }
    } while (response.getStatus() == 429);

    return response;
}
项目:conquest-engine    文件:RunGame.java   
private void finish(IORobot bot1, IORobot bot2) throws InterruptedException
{
    bot1.finish();
    Thread.sleep(200);

    bot2.finish();
    Thread.sleep(200);

    Thread.sleep(200);

    // write everything
    // String outputFile = this.writeOutputFile(this.gameId, this.engine.winningPlayer());
    this.saveGame(bot1, bot2);

       System.exit(0);
}
项目:libbluray    文件:ImageFrameAccurateAnimation.java   
public void prepareImages() {
    if (prepared) {
        return;
    }

    MediaTracker mt = new MediaTracker(this);
    for (int i = 0; i < images.length; i++) {
        mt.addImage(images[i], i);
    }
    try {
        mt.waitForAll();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    for (int i = 0; i < images.length; i++) {
        mt.removeImage(images[i], i);
    }

    if (params.scaleFactor != 1) {
        // TODO: scale if needed
        logger.unimplemented("image_scaling");
    }

    prepared = true;
}
项目:ShaderEditor    文件:ShaderRenderer.java   
public byte[] getThumbnail() {
    // settings thumbnail to null triggers
    // the capture on the OpenGL thread in
    // onDrawFrame()
    thumbnail = null;

    try {
        for (int trys = 10;
                trys-- > 0 && program > 0 && thumbnail == null; ) {
            Thread.sleep(100);
        }
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }

    // don't clone() because the data doesn't need to be
    // protected from modification what means copying would
    // only mean using more memory than necessary
    return thumbnail;
}
项目:yar    文件:RegistryModuleBindTest.java   
@Test
public void testBindSupplierWithAnnotation() throws java.util.concurrent.TimeoutException, InterruptedException {
    final BlockingSupplierRegistry registry = newBlockingSupplierRegistry();
    Module module = newRegistryDeclarationModule(registry);
    final Named test = Names.named("test");
    final Key<MyInterface> key = Key.get(MyInterface.class, test);
    final Key<Supplier<MyInterface>> supplierKey = Key.get(new TypeLiteral<Supplier<MyInterface>>() {
    }, test);
    Id<MyInterface> id = GuiceId.of(key);
    getMyInterfaceRegistration(registry, id);
    RegistryModule supplierBindingRegistryModule = new RegistryModule() {
        @Override
        protected void configureRegistry() {
            bind(supplierKey).toRegistry();
        }
    };
    Injector injector = createInjector(module, supplierBindingRegistryModule);
    Supplier<MyInterface> supplier = injector.getInstance(supplierKey);
    assertThat(supplier, is(not(nullValue())));
    assertThat(injector.getInstance(Key.get(new TypeLiteral<BlockingSupplier<MyInterface>>(){},test)).getSync(100, TimeUnit.MICROSECONDS), is(not(nullValue())));
    assertThat(supplier.get(), is(not(nullValue())));

}
项目:yar    文件:RegistryProviderImplTest.java   
@Test
public void testInterruptedExceptionWithDefaultTimeout() throws Exception {
    //given
    when(registry.get(GuiceId.of(STRING_KEY))).thenReturn(blockingSupplier);
    when(blockingSupplier.defaultTimeout()).thenReturn(1L);
    when(blockingSupplier.defaultTimeUnit()).thenReturn(DAYS);
    doThrow(InterruptedException.class).when(blockingSupplier).getSync(1L, DAYS);
    //when
    RegistryProviderImpl<String> provider = new RegistryProviderImpl<>(STRING_KEY);
    provider.setRegistry(registry);
    try {
        provider.get();
        Assert.fail("Expected " + org.javabits.yar.InterruptedException.class.getName() + " exception.");
    } catch (org.javabits.yar.InterruptedException e) {
        //then test and clear the interrupted status
        assertThat(Thread.interrupted(), is(true));        }
}
项目:bitworker    文件:PeerExchange.java   
/**
 * Dynamically determines an amount of time to sleep, based on the
 * average read/write throughput.
 * 
 * <p>
 * The algorithm is functional, but could certainly be improved upon.
 * One obvious drawback is that with large changes in
 * <code>maxRate</code>, it will take a while for the sleep time to
 * adjust and the throttled rate to "smooth out."
 * </p>
 * 
 * <p>
 * Ideally, it would calculate the optimal sleep time necessary to hit
 * a desired throughput rather than continuously adjust toward a goal.
 * </p>
 * 
 * @param maxRate the target rate in kB/second.
 * @param messageSize the size, in bytes, of the last message read/written.
 * @param message the last <code>PeerMessage</code> read/written.
 */
protected void rateLimit(double maxRate, long messageSize, PeerMessage message) {
    if (message.getType() != Type.PIECE || maxRate <= 0) {
        return;
    }

    try {
        this.rate.add(messageSize);

        // Continuously adjust the sleep time to try to hit our target
        // rate limit.
        if (rate.get() > (maxRate * 1024)) {
            Thread.sleep(this.sleep);
            this.sleep += 50;
        } else {
            this.sleep = this.sleep > 50
                ? this.sleep - 50
                : 0;
        }
    } catch (InterruptedException e) {
        // Not critical, eat it.
    }
}
项目:TLIVideoConferencingv2    文件:UserSession.java   
public void clearRecording() {
  log.info("USER {}: END recording in room {}", name, roomName);
  recorderCaller.stop();
  recorderCaller.release();
  // conversion
  log.info("should run {}", pendingConversion);
  if (pendingConversion == true) {
    log.info("Run Conversion");
    new Thread(new Runnable() {
      public void run(){
         try {
          log.info("Running: {}", "ffmpeg -i " + RECORDING_PATH + preConvertedName + RECORDING_EXT + " -strict -2 -q:vscale 0 " + RECORDING_PATH + preConvertedName + ".mp4");
          Process proc = Runtime.getRuntime().exec("ffmpeg -i " + RECORDING_PATH + preConvertedName + RECORDING_EXT + " -strict -2 -q:vscale 0 " + RECORDING_PATH + preConvertedName + ".mp4");
          proc.waitFor();
          log.info("Running: {}", "ffmpeg -i " + RECORDING_PATH + preConvertedName + ".mp4 -profile:v baseline -level 3.0 -s 1280x960 -start_number 0 -hls_time 10 -hls_list_size 0 -strict -2 -f hls " + RECORDING_PATH + preConvertedName +".m3u8");
          Runtime.getRuntime().exec("ffmpeg -i " + RECORDING_PATH + preConvertedName + ".mp4 -profile:v baseline -level 3.0 -s 1280x960 -start_number 0 -hls_time 10 -hls_list_size 0 -strict -2 -f hls " + RECORDING_PATH + preConvertedName +".m3u8");
        }
        catch (IOException e) {
          log.info(e.getMessage());
        }
        catch (InterruptedException ie) {
          log.info(ie.getMessage());
        }
      }
    }).start();
  }
  pendingConversion = false;
}