org.testng.TestException Java Examples

The following examples show how to use org.testng.TestException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PdfTableReaderTest.java    From pdf-table with MIT License 6 votes vote down vote up
@Test
public void multiThreadedSavePdfPageAsPNG() throws IOException {
    long start = System.currentTimeMillis();
    PdfTableReader reader = new PdfTableReader();
    ExecutorService executor = Executors.newFixedThreadPool(THREAD_COUNT);

    List<Future<Boolean>> futures = new ArrayList<>();
    for (final int pageNum : IntStream.rangeClosed(1, PDFdoc.getNumberOfPages()).toArray()) {
        Callable<Boolean> callable = () -> {
            reader.savePdfPageAsPNG(PDFdoc, pageNum, TEST_OUT_PATH);
            return true;
        };
        futures.add(executor.submit(callable));
    }

    try {
        for (Future<Boolean> f : futures) {
            f.get();
        }
    } catch (Exception e) {
        throw new TestException(e);
    }

    long end = System.currentTimeMillis();
    System.out.println("save page image - multi thread: " + (end - start) / 1000.0);
}
 
Example #2
Source File: DerSpec.java    From swim with Apache License 2.0 6 votes vote down vote up
public static void assertEncodes(Value value, Data data) {
  final ByteBuffer expected = ByteBuffer.wrap(data.toByteArray());
  for (int i = expected.capacity(), n = expected.capacity(); i <= n; i += 1) {
    final ByteBuffer actual = ByteBuffer.allocate(n);
    OutputBuffer<?> output = Binary.outputBuffer(actual).isPart(true);
    Encoder<?, ?> encoder = Der.structureEncoder().encoder(value);
    assertTrue(encoder.isCont());
    assertFalse(encoder.isError());
    assertFalse(encoder.isDone());
    output = output.limit(i).isPart(true);
    encoder = encoder.pull(output);
    output = output.limit(n).isPart(false);
    encoder = encoder.pull(output);
    if (encoder.isError()) {
      throw new TestException(encoder.trap());
    }
    assertFalse(encoder.isCont());
    assertTrue(encoder.isDone());
    actual.flip();
    if (!actual.equals(expected)) {
      final Output<String> message = Unicode.stringOutput();
      message.write("expected ").debug(Data.from(expected)).write(" but found ").debug(Data.from(actual));
      fail(message.toString());
    }
  }
}
 
Example #3
Source File: MqttAssertions.java    From swim with Apache License 2.0 6 votes vote down vote up
public static <T> void assertDecodes(Decoder<T> decodee, InputBuffer input, T expected) {
  for (int i = 0, n = input.remaining(); i <= n; i += 1) {
    Decoder<?> decoder = decodee;
    assertTrue(decoder.isCont());
    assertFalse(decoder.isDone());
    assertFalse(decoder.isError());
    input = input.index(0).limit(i).isPart(true);
    decoder = decoder.feed(input);
    input = input.limit(n).isPart(false);
    decoder = decoder.feed(input);
    if (decoder.isError()) {
      throw new TestException(decoder.trap());
    }
    assertFalse(decoder.isCont());
    assertTrue(decoder.isDone());
    assertFalse(decoder.isError());
    assertEquals(decoder.bind(), expected);
  }
}
 
Example #4
Source File: MqttAssertions.java    From swim with Apache License 2.0 6 votes vote down vote up
public static void assertEncodes(Encoder<?, ?> part, ByteBuffer expected) {
  for (int i = 0, n = expected.capacity(); i <= n; i += 1) {
    final ByteBuffer actual = ByteBuffer.allocate(n);
    OutputBuffer<?> output = Binary.outputBuffer(actual).isPart(true);
    Encoder<?, ?> encoder = part;
    assertTrue(encoder.isCont());
    assertFalse(encoder.isError());
    assertFalse(encoder.isDone());
    output = output.limit(i).isPart(true);
    encoder = encoder.pull(output);
    output = output.limit(n).isPart(false);
    encoder = encoder.pull(output);
    if (encoder.isError()) {
      throw new TestException(encoder.trap());
    }
    assertFalse(encoder.isCont());
    assertTrue(encoder.isDone());
    actual.flip();
    if (!actual.equals(expected)) {
      final Output<String> message = Unicode.stringOutput();
      message.write("expected ").debug(Data.from(expected)).write(" but found ").debug(Data.from(actual));
      fail(message.toString());
    }
  }
}
 
Example #5
Source File: Assertions.java    From swim with Apache License 2.0 6 votes vote down vote up
public static <T> void assertDecodes(Decoder<T> decodee, InputBuffer input, T expected) {
  for (int i = 0, n = input.remaining(); i <= n; i += 1) {
    Decoder<?> decoder = decodee;
    assertTrue(decoder.isCont());
    assertFalse(decoder.isDone());
    assertFalse(decoder.isError());
    input = input.index(0).limit(i).isPart(true);
    decoder = decoder.feed(input);
    input = input.limit(n).isPart(false);
    decoder = decoder.feed(input);
    if (decoder.isError()) {
      throw new TestException(decoder.trap());
    }
    assertFalse(decoder.isCont());
    assertTrue(decoder.isDone());
    assertFalse(decoder.isError());
    assertEquals(decoder.bind(), expected);
  }
}
 
Example #6
Source File: JsonWriterSpec.java    From swim with Apache License 2.0 6 votes vote down vote up
public static void assertWrites(Item item, byte... expected) {
  for (int i = 0, n = expected.length; i <= n; i += 1) {
    final byte[] actual = new byte[n];
    OutputBuffer<?> buffer = Binary.outputBuffer(actual);
    buffer = buffer.limit(i);
    Writer<?, ?> writer = Json.write(item, Utf8.decodedOutput(buffer).isPart(true));
    buffer = buffer.limit(buffer.capacity());
    writer = writer.pull(Utf8.decodedOutput(buffer).isPart(false));
    if (writer.isError()) {
      throw new TestException(writer.trap());
    }
    assertFalse(writer.isCont());
    assertTrue(writer.isDone());
    assertEquals(actual, expected);
  }
}
 
Example #7
Source File: Assertions.java    From swim with Apache License 2.0 6 votes vote down vote up
public static <T> void assertDecodes(Decoder<T> decodee, InputBuffer input, T expected) {
  for (int i = 0, n = input.remaining(); i <= n; i += 1) {
    Decoder<?> decoder = decodee;
    assertTrue(decoder.isCont());
    assertFalse(decoder.isDone());
    assertFalse(decoder.isError());
    input = input.index(0).limit(i).isPart(true);
    decoder = decoder.feed(input);
    input = input.limit(n).isPart(false);
    decoder = decoder.feed(input);
    if (decoder.isError()) {
      throw new TestException(decoder.trap());
    }
    assertFalse(decoder.isCont());
    assertTrue(decoder.isDone());
    assertFalse(decoder.isError());
    assertEquals(decoder.bind(), expected);
  }
}
 
Example #8
Source File: WsFrameDeflaterSpec.java    From swim with Apache License 2.0 6 votes vote down vote up
static void assertEncodes(WsEncoder ws, WsFrame<?> frame, Data encoded, int... bufferSizes) {
  final byte[] actual = new byte[encoded.size() + 4];
  int bufferSize = encoded.size() + 4;
  Encoder<?, ?> frameEncoder = ws.frameEncoder(frame);
  for (int k = 0, i = 0, n = actual.length; i < n; i += bufferSize) {
    if (k < bufferSizes.length) {
      bufferSize = bufferSizes[k];
      k += 1;
    }
    frameEncoder = frameEncoder.pull(Binary.outputBuffer(actual, i, Math.min(bufferSize, actual.length - i))
        .isPart(actual.length - i > bufferSize));
    if (frameEncoder.isError()) {
      throw new TestException(frameEncoder.trap());
    }
  }
  assertTrue(frameEncoder.isDone());
  assertEquals(Data.wrap(actual, 0, encoded.size()), encoded);
}
 
Example #9
Source File: WsFrameEncoderSpec.java    From swim with Apache License 2.0 6 votes vote down vote up
static void assertEncodes(WsEncoder ws, WsFrame<?> frame, Data encoded, int... bufferSizes) {
  final byte[] actual = new byte[encoded.size()];
  int bufferSize = encoded.size();
  Encoder<?, ?> frameEncoder = ws.frameEncoder(frame);
  for (int k = 0, i = 0, n = actual.length; i < n; i += bufferSize) {
    if (k < bufferSizes.length) {
      bufferSize = bufferSizes[k];
      k += 1;
    }
    frameEncoder = frameEncoder.pull(Binary.outputBuffer(actual, i, Math.min(bufferSize, actual.length - i))
        .isPart(actual.length - i > bufferSize));
    if (frameEncoder.isError()) {
      throw new TestException(frameEncoder.trap());
    }
  }
  assertTrue(frameEncoder.isDone());
  assertEquals(Data.wrap(actual), encoded);
}
 
Example #10
Source File: IpModemBehaviors.java    From swim with Apache License 2.0 6 votes vote down vote up
@Test
public void testClientConnectError() {
  final Theater stage = new Theater();
  final IpEndpoint endpoint = new IpEndpoint(stage);
  final CountDownLatch clientDisconnect = new CountDownLatch(1);
  final AbstractIpModem<Object, Object> modem = new AbstractIpModem<Object, Object>() {
    @Override
    public void didDisconnect() {
      clientDisconnect.countDown();
    }
  };

  try {
    stage.start();
    endpoint.start();
    connect(endpoint, modem);
    clientDisconnect.await();
  } catch (InterruptedException cause) {
    throw new TestException(cause);
  } finally {
    endpoint.stop();
    stage.stop();
  }
}
 
Example #11
Source File: PdfTableReaderTest.java    From pdf-table with MIT License 6 votes vote down vote up
@Test
public void multiThreadedSavePdfTablePageDebugImage() throws IOException {
    long start = System.currentTimeMillis();
    PdfTableReader reader = new PdfTableReader();
    ExecutorService executor = Executors.newFixedThreadPool(THREAD_COUNT);

    List<Future<Boolean>> futures = new ArrayList<>();
    for (final int pageNum : IntStream.rangeClosed(1, PDFdoc.getNumberOfPages()).toArray()) {
        Callable<Boolean> callable = () -> {
            reader.savePdfTablePageDebugImage(PDFdoc, pageNum, TEST_OUT_PATH);
            return true;
        };
        futures.add(executor.submit(callable));
    }

    try {
        for (Future<Boolean> f : futures) {
            f.get();
        }
    } catch (Exception e) {
        throw new TestException(e);
    }

    long end = System.currentTimeMillis();
    System.out.println("save debug images - multi thread: " + (end - start) / 1000.0);
}
 
Example #12
Source File: RetryConfigBuilderTest_WithValidationTest.java    From retry4j with MIT License 6 votes vote down vote up
@Test
public void verifySpecifyingMultipleBuildInAndCustomExceptionStrategiesThrowsException_specificExceptions() {
    try {
        retryConfigBuilder
                .retryOnSpecificExceptions(TestException.class)
                .retryOnCustomExceptionLogic(ex -> ex.getMessage().contains("should retry!"))
                .withFixedBackoff()
                .withDelayBetweenTries(Duration.ofMillis(1))
                .withMaxNumberOfTries(3)
                .build();
        fail("Expected InvalidRetryConfigException but one wasn't thrown!");
    } catch (InvalidRetryConfigException e) {
        assertThat(e.getMessage())
                .isEqualTo(RetryConfigBuilder.CAN_ONLY_SPECIFY_CUSTOM_EXCEPTION_STRAT__ERROR_MSG);
    }
}
 
Example #13
Source File: RetryConfigBuilderTest_WithValidationTest.java    From retry4j with MIT License 6 votes vote down vote up
@Test
public void verifySpecifyingMultipleBuildInAndCustomExceptionStrategiesThrowsException_excludingExceptions() {
    try {
        retryConfigBuilder
                .retryOnAnyExceptionExcluding(TestException.class)
                .retryOnCustomExceptionLogic(ex -> ex.getMessage().contains("should retry!"))
                .withFixedBackoff()
                .withDelayBetweenTries(Duration.ofMillis(1))
                .withMaxNumberOfTries(3)
                .build();
        fail("Expected InvalidRetryConfigException but one wasn't thrown!");
    } catch (InvalidRetryConfigException e) {
        assertThat(e.getMessage())
                .isEqualTo(RetryConfigBuilder.CAN_ONLY_SPECIFY_CUSTOM_EXCEPTION_STRAT__ERROR_MSG);
    }
}
 
Example #14
Source File: HierarchicalAckableTest.java    From incubator-gobblin with Apache License 2.0 6 votes vote down vote up
@Test
public void testChildNacked() throws Exception {
  BasicAckableForTesting ackable = new BasicAckableForTesting();
  HierarchicalAckable hierarchicalAckable = new HierarchicalAckable(Lists.newArrayList(ackable));

  Ackable child1 = hierarchicalAckable.newChildAckable();
  Ackable child2 = hierarchicalAckable.newChildAckable();

  child2.ack();
  Assert.assertEquals(ackable.acked, 0);
  Assert.assertEquals(ackable.nacked, 0);

  hierarchicalAckable.close();
  Assert.assertEquals(ackable.acked, 0);
  Assert.assertEquals(ackable.nacked, 0);

  child1.nack(new TestException("test"));
  Assert.assertEquals(ackable.acked, 0);
  Assert.assertEquals(ackable.nacked, 1);

  Assert.assertNotNull(ackable.throwable);
  Assert.assertTrue(ackable.throwable instanceof HierarchicalAckable.ChildrenFailedException);
  Assert.assertEquals(((HierarchicalAckable.ChildrenFailedException) ackable.throwable).getFailureCauses().size(), 1);
}
 
Example #15
Source File: SVKmerShortUnitTest.java    From gatk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test(dataProvider = "maskData", groups = "sv")
public void testMaskedKmers(final String seq1, final String seq2, final byte[] maskBytes, final boolean equal) {

    if (seq1.length() != seq2.length()) {
        throw new TestException("Kmer sequences must be of same length");
    }
    final int K = seq1.length();

    final SVKmerShort kmer1 = (SVKmerShort)SVKmerizer.toKmer(seq1, new SVKmerShort(K));
    final SVKmerShort kmer2 = (SVKmerShort)SVKmerizer.toKmer(seq2, new SVKmerShort(K));
    final SVKmerShort mask = SVKmerShort.getMask(maskBytes, K);

    if (equal) {
        Assert.assertEquals(kmer1.mask(mask), kmer2.mask(mask));
    } else {
        Assert.assertNotEquals(kmer1.mask(mask), kmer2.mask(mask));
    }
}
 
Example #16
Source File: PSScorerTest.java    From gatk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private static String getTestCigar(final int readLength, final int insertionLength, final int deletionLength, final int clipLength) {
    final int numMatchOrMismatch = readLength - insertionLength - clipLength;
    if (numMatchOrMismatch < 0) {
        throw new TestException("Clip length plus insertions plus clipping was greater than read length");
    }
    String cigar = "";
    if (clipLength > 0) {
        cigar = cigar + clipLength + "S";
    }
    if (insertionLength > 0) {
        cigar = cigar + insertionLength + "I";
    }
    if (deletionLength > 0) {
        cigar = cigar + deletionLength + "D";
    }
    if (numMatchOrMismatch > 0) {
        cigar = cigar + numMatchOrMismatch + "M";
    }
    return cigar;
}
 
Example #17
Source File: PSScorerTest.java    From gatk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private static GATKRead generateRead(final int length, final List<Integer> NM, final List<Integer> clip,
                                     final List<Integer> insert, final List<Integer> delete,
                                     final List<String> contig, final String altTag) {
    final GATKRead read = ArtificialReadUtils.createRandomRead(length);
    read.setAttribute("NM", NM.get(0));
    read.setPosition(contig.get(0), 1);
    read.setCigar(getTestCigar(length, insert.get(0), delete.get(0), clip.get(0)));
    if (NM.size() > 1) {
        String tagValue = "";
        for (int i = 1; i < NM.size(); i++) {
            if (altTag.equals("XA")) {
                tagValue += contig.get(i) + ",+1," + getTestCigar(length, insert.get(i), delete.get(i), clip.get(i)) + "," + NM.get(i) + ";";
            } else if (altTag.equals("SA")) {
                tagValue += contig.get(i) + ",1,+," + getTestCigar(length, insert.get(i), delete.get(i), clip.get(i)) + ",0," + NM.get(i) + ";";
            } else {
                throw new TestException("Unknown tag " + altTag);
            }
        }
        read.setAttribute(altTag, tagValue);
    }
    return read;
}
 
Example #18
Source File: DeflateSpec.java    From swim with Apache License 2.0 6 votes vote down vote up
static void assertDeflates(byte[] inflated, byte[] deflated, int wrap, int windowBits, int flush, int bufferSize) {
  final byte[] actual = new byte[deflated.length];
  Encoder<?, byte[]> deflater = new Deflate<>(Binary.byteArrayWriter(inflated), wrap, Deflate.Z_DEFAULT_COMPRESSION, windowBits).flush(flush);
  for (int i = 0; i < actual.length; i += bufferSize) {
    deflater = deflater.pull(Binary.outputBuffer(actual, i, Math.min(bufferSize, actual.length - i)).isPart(actual.length - i > bufferSize));

    if (deflater.isError()) {
      throw new TestException(deflater.trap());
    }
  }

  assertTrue(deflater.isDone());

  for (int i = 0, n = deflated.length; i < n; i += 1) {
    if ((actual[i] & 0xff) != (deflated[i] & 0xff)) {
      fail("expected 0x" + Integer.toHexString(deflated[i] & 0xff)
          + ", but found 0x" + Integer.toHexString(actual[i] & 0xff)
          + " at index " + i);
    }
  }
}
 
Example #19
Source File: InflateSpec.java    From swim with Apache License 2.0 6 votes vote down vote up
static void assertInflates(byte[] deflated, byte[] inflated, int wrap, int windowBits, int bufferSize) {
  final Output<byte[]> output = Binary.byteArrayOutput(inflated.length);
  Decoder<byte[]> inflater = new Inflate<byte[]>(Binary.outputParser(output), wrap, windowBits);
  for (int i = 0; i < deflated.length; i += bufferSize) {
    inflater = inflater.feed(Binary.inputBuffer(deflated, i, Math.min(bufferSize, deflated.length - i)).isPart(deflated.length - i > bufferSize));
    if (inflater.isError()) {
      throw new TestException(inflater.trap());
    }
  }


  assertTrue(inflater.isDone());
  final byte[] actual = output.bind();
  assertEquals(actual.length, inflated.length);
  for (int i = 0, n = inflated.length; i < n; i += 1) {
    if ((actual[i] & 0xff) != (inflated[i] & 0xff)) {
      fail("expected 0x" + Integer.toHexString(inflated[i] & 0xff)
          + ", but found 0x" + Integer.toHexString(actual[i] & 0xff)
          + " at index " + i);
    }
  }
}
 
Example #20
Source File: DeflateUtil.java    From swim with Apache License 2.0 6 votes vote down vote up
/**
 * Reads a given resources by its name removing carriage returns as requested
 *
 * @param resource name of the desired resource
 * @param removeCr whether or not to strip carriage returns
 * @return the requested resource as a byte array
 */
static byte[] readResource(String resource, boolean removeCr) {
  try (InputStream input = DeflateSpec.class.getResourceAsStream(resource)) {
    final byte[] buffer = new byte[4096];
    final ByteArrayOutputStream output = new ByteArrayOutputStream();
    int count;

    while (true) {
      count = input.read(buffer);
      if (count <= 0) {
        break;
      }
      output.write(buffer, 0, count);
    }

    return removeCarriageReturns(output, removeCr);
  } catch (IOException cause) {
    throw new TestException(cause);
  }
}
 
Example #21
Source File: HttpAssertions.java    From swim with Apache License 2.0 6 votes vote down vote up
public static <T> void assertDecodes(Decoder<T> decodee, InputBuffer input, T expected) {
  for (int i = 0, n = input.remaining(); i <= n; i += 1) {
    Decoder<?> decoder = decodee;
    assertTrue(decoder.isCont());
    assertFalse(decoder.isDone());
    assertFalse(decoder.isError());
    input = input.index(0).limit(i).isPart(true);
    decoder = decoder.feed(input);
    input = input.limit(n).isPart(false);
    decoder = decoder.feed(input);
    if (decoder.isError()) {
      throw new TestException(decoder.trap());
    }
    assertFalse(decoder.isCont());
    assertTrue(decoder.isDone());
    assertFalse(decoder.isError());
    assertEquals(decoder.bind(), expected);
  }
}
 
Example #22
Source File: HttpAssertions.java    From swim with Apache License 2.0 6 votes vote down vote up
public static void assertWrites(HttpPart part, byte... expected) {
  for (int i = 0, n = expected.length; i <= n; i += 1) {
    final byte[] actual = new byte[n];
    OutputBuffer<?> output = Binary.outputBuffer(actual);
    output = output.limit(i).isPart(true);
    Writer<?, ?> writer = Utf8.writeEncoded(part.httpWriter(), output);
    output = output.limit(output.capacity()).isPart(false);
    writer = writer.pull(output);
    if (writer.isError()) {
      throw new TestException(writer.trap());
    }
    assertFalse(writer.isCont());
    assertTrue(writer.isDone());
    assertEquals(actual, expected);
  }
}
 
Example #23
Source File: HttpAssertions.java    From swim with Apache License 2.0 6 votes vote down vote up
public static void assertEncodes(Encoder<?, ?> part, ByteBuffer expected) {
  final ByteBuffer actual = ByteBuffer.allocate(expected.remaining() + 48);
  final OutputBuffer<?> output = Binary.outputBuffer(actual).isPart(true);
  Encoder<?, ?> encoder = part;
  assertTrue(encoder.isCont());
  assertFalse(encoder.isError());
  assertFalse(encoder.isDone());
  while (encoder.isCont()) {
    encoder = encoder.pull(output);
  }
  if (encoder.isError()) {
    throw new TestException(encoder.trap());
  }
  assertFalse(encoder.isCont());
  assertTrue(encoder.isDone());
  actual.flip();
  if (!actual.equals(expected)) {
    final Output<String> message = Unicode.stringOutput();
    message.write("expected ")
        .debug(new String(expected.array(), expected.arrayOffset(), expected.remaining()))
        .write(" but found ")
        .debug(new String(actual.array(), actual.arrayOffset(), actual.remaining()));
    fail(message.toString());
  }
}
 
Example #24
Source File: Assertions.java    From swim with Apache License 2.0 6 votes vote down vote up
public static <T> void assertDecodes(Decoder<T> decodee, InputBuffer input, T expected) {
  for (int i = 0, n = input.remaining(); i <= n; i += 1) {
    Decoder<?> decoder = decodee;
    assertTrue(decoder.isCont());
    assertFalse(decoder.isDone());
    assertFalse(decoder.isError());
    input = input.index(0).limit(i).isPart(true);
    decoder = decoder.feed(input);
    input = input.limit(n).isPart(false);
    decoder = decoder.feed(input);
    if (decoder.isError()) {
      throw new TestException(decoder.trap());
    }
    assertFalse(decoder.isCont());
    assertTrue(decoder.isDone());
    assertFalse(decoder.isError());
    assertEquals(decoder.bind(), expected);
  }
}
 
Example #25
Source File: ReconWriterSpec.java    From swim with Apache License 2.0 6 votes vote down vote up
public static void assertWrites(Item item, byte... expected) {
  final int size = Recon.structureWriter().sizeOfItem(item);
  final int n = expected.length;
  if (size != n) {
    fail("expected " + n + " bytes, but found " + size + " bytes: " + Recon.toString(item));
  }
  for (int i = 0; i <= n; i += 1) {
    final byte[] actual = new byte[n];
    OutputBuffer<?> buffer = Binary.outputBuffer(actual);
    buffer = buffer.limit(i);
    Writer<?, ?> writer = Recon.write(item, Utf8.decodedOutput(buffer).isPart(true));
    buffer = buffer.limit(buffer.capacity());
    writer = writer.pull(Utf8.decodedOutput(buffer).isPart(false));
    if (writer.isError()) {
      throw new TestException(writer.trap());
    }
    assertFalse(writer.isCont());
    assertTrue(writer.isDone());
    assertEquals(actual, expected);
  }
}
 
Example #26
Source File: IpSocketBehaviors.java    From swim with Apache License 2.0 6 votes vote down vote up
@Test
public void testClientConnectError() {
  final Theater stage = new Theater();
  final IpEndpoint endpoint = new IpEndpoint(stage);
  final CountDownLatch clientDisconnect = new CountDownLatch(1);
  final AbstractIpSocket client = new AbstractIpSocket() {
    @Override
    public void didDisconnect() {
      clientDisconnect.countDown();
    }
  };

  try {
    stage.start();
    endpoint.start();
    connect(endpoint, client);
    clientDisconnect.await();
  } catch (InterruptedException cause) {
    throw new TestException(cause);
  } finally {
    client.close();
    endpoint.stop();
    stage.stop();
  }
}
 
Example #27
Source File: DerSpec.java    From swim with Apache License 2.0 6 votes vote down vote up
public static <T> void assertDecodes(Decoder<T> decodee, InputBuffer input, T expected) {
  for (int i = 0, n = input.remaining(); i <= n; i += 1) {
    Decoder<?> decoder = decodee;
    assertTrue(decoder.isCont());
    assertFalse(decoder.isDone());
    assertFalse(decoder.isError());
    input = input.index(0).limit(i).isPart(true);
    decoder = decoder.feed(input);
    input = input.limit(n).isPart(false);
    decoder = decoder.feed(input);
    if (decoder.isError()) {
      throw new TestException(decoder.trap());
    }
    assertFalse(decoder.isCont());
    assertTrue(decoder.isDone());
    assertFalse(decoder.isError());
    assertEquals(decoder.bind(), expected);
  }
}
 
Example #28
Source File: ReconWriterSpec.java    From swim with Apache License 2.0 6 votes vote down vote up
public static void assertWritesBlock(Item item, byte... expected) {
  final int size = Recon.structureWriter().sizeOfBlockItem(item);
  final int n = expected.length;
  if (size != n) {
    fail("expected " + n + " bytes, but found " + size + " bytes: " + Recon.toBlockString(item));
  }
  for (int i = 0; i <= n; i += 1) {
    final byte[] actual = new byte[n];
    OutputBuffer<?> buffer = Binary.outputBuffer(actual);
    buffer = buffer.limit(i);
    Writer<?, ?> writer = Recon.writeBlock(item, Utf8.decodedOutput(buffer).isPart(true));
    buffer = buffer.limit(buffer.capacity());
    writer = writer.pull(Utf8.decodedOutput(buffer).isPart(false));
    if (writer.isError()) {
      throw new TestException(writer.trap());
    }
    assertFalse(writer.isCont());
    assertTrue(writer.isDone());
    assertEquals(actual, expected);
  }
}
 
Example #29
Source File: ScriptHelperTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
@Override
public int execute(Map flags2, List<String> script, String summaryForLogging) {
    if (failExecution) {
        throw new TestException("Simulated driver exception");
    }
    return 0;
}
 
Example #30
Source File: ScriptHelperTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
public int execute(List<String> script, String summaryForLogging) {
    if (failExecution) {
        throw new TestException("Simulated driver exception");
    }
    return 0;
}