@Theory
 @SuppressWarnings({"unchecked", "rawtypes"})
 public void differentMatchersHaveDifferentDescriptions(
     Matcher matcher1, Matcher matcher2, Object value) {
   assumeThat(value, matcher1);
   assumeThat(value, not(matcher2));
   assertThat(matcher1.toString(), not(matcher2.toString()));
 }
  @Theory
  public void obtainValidConnection(String jndiName) {
    assumeThat(jndiName, notNullValue());
    assumeTrue(jndiName.startsWith("java:"));
    assumeThat(jndiName, not(containsString("invalid")));

    component.setValue(jndiName);
    Connection connection = converter.getConnection(facesEnv.getFacesContext(), component);
    assertThat(connection, notNullValue());
  }
Esempio n. 3
0
  @Theory
  public void testVectorResult(UnaryArithmeticFactory factory, RAbstractVector originalOperand) {
    RAbstractVector operand = originalOperand.copy();
    assumeThat(operand, is(not(instanceOf(RScalarVector.class))));

    Object result = executeArithmetic(factory, operand);
    Assert.assertFalse(isPrimitive(result));
    assumeThat(result, is(instanceOf(RAbstractVector.class)));
    RAbstractVector resultCast = (RAbstractVector) result;

    assertThat(resultCast.getLength(), is(equalTo(operand.getLength())));
  }
  @Test
  public void publishReceivedCountsProcessedMessages()
      throws BufferOutOfCapacityException, ProcessingDisabledException {
    final PublishMessage message =
        new PublishMessage(
            "test", QoS.AT_LEAST_ONCE, "{\"version\":\"1.1\", \"message\":\"test\"}");

    assumeThat(metricRegistry.getMeters().get("test.incompleteMessages").getCount(), is(0l));
    assumeThat(metricRegistry.getMeters().get("test.processedMessages").getCount(), is(0l));

    listener.publishReceived(client, message);

    assertThat(metricRegistry.getMeters().get("test.incompleteMessages").getCount(), is(0l));
    assertThat(metricRegistry.getMeters().get("test.processedMessages").getCount(), is(1l));
  }
Esempio n. 5
0
  @Test
  public void whenChannelOverflowsThrowException() throws Exception {
    assumeThat(policy, is(OverflowPolicy.THROW));
    assumeThat(mailboxSize, greaterThan(0));

    final Channel<Integer> ch = newChannel();

    int i = 0;
    try {
      for (i = 0; i < 10; i++) ch.send(i);
      fail();
    } catch (QueueCapacityExceededException e) {
      System.out.println("i = " + i);
    }
  }
  @Test
  public void publishReceivedCountsIncomingMessages() {
    assumeThat(metricRegistry.getMeters().get("test.incomingMessages").getCount(), is(0l));
    listener.publishReceived(client, new PublishMessage("test", QoS.AT_LEAST_ONCE));

    assertThat(metricRegistry.getMeters().get("test.incomingMessages").getCount(), is(1l));
  }
  @Theory
  public void succeedsWhenCollectionContainsZeroItemsMatchingMatcher(
      Collection<Object> collection) {
    assumeThat(collection, hasItem(isA(FourConstant.class)));

    assertThat(collection, CollectionMatchers.hasZeroItemsWith("value", is(not(4))));
  }
  @Test
  public void testConnectCancellation() throws Throwable {
    // Check if the test can be executed or should be skipped because of no network/internet
    // connection
    // See https://github.com/netty/netty/issues/1474
    boolean badHostTimedOut = true;
    Socket socket = new Socket();
    try {
      socket.connect(new InetSocketAddress(BAD_HOST, BAD_PORT), 10);
    } catch (ConnectException e) {
      badHostTimedOut = false;
      // is thrown for no route to host when using Socket connect
    } catch (Exception e) {
      // ignore
    } finally {
      try {
        socket.close();
      } catch (IOException e) {
        // ignore
      }
    }

    assumeThat(
        "The connection attempt to " + BAD_HOST + " does not time out.", badHostTimedOut, is(true));

    run();
  }
  @Before
  public void setUp() throws Exception {
    this.cache = MANAGER.getEhcache("test-config");
    assumeThat(cache, is(CoreMatchers.notNullValue()));

    this.registry = SharedMetricRegistries.getOrCreate("cache-metrics");
  }
Esempio n. 10
0
  @Theory
  public void failsWhenCollectionContainsOneItemMatchingMatcher(Collection<Object> collection) {
    assumeThat(collection, not(hasItem(isA(FourConstant.class))));
    expectAssertionErrorForIncorrectNumberOfMatches("is not <4>", 1);

    assertThat(collection, CollectionMatchers.hasZeroItemsWith("value", is(not(4))));
  }
Esempio n. 11
0
  @Test
  public void testBlockingChannelSendingThread() throws Exception {
    assumeThat(policy, is(OverflowPolicy.BLOCK));
    final Channel<Integer> ch = newChannel();

    Fiber<Integer> fib =
        new Fiber<Integer>(
                fjPool,
                new SuspendableCallable<Integer>() {
                  @Override
                  public Integer run() throws SuspendExecution, InterruptedException {
                    int i = 0;
                    while (ch.receive() != null) {
                      i++;
                      Fiber.sleep(50);
                    }
                    return i;
                  }
                })
            .start();

    for (int i = 0; i < 10; i++) ch.send(i);
    ch.close();

    assertThat(fib.get(), is(10));
  }
Esempio n. 12
0
  @Before
  public void setUp() throws Exception {
    assumeThat(TD_API_KEY, not(isEmptyOrNullString()));
    projectDir = folder.getRoot().toPath().toAbsolutePath().normalize();
    config = folder.newFile().toPath();
    Files.write(config, asList("secrets.td.apikey = " + TD_API_KEY));
    outfile = projectDir.resolve("outfile");

    client = TDClient.newBuilder(false).setApiKey(TD_API_KEY).build();
    database = "tmp_" + UUID.randomUUID().toString().replace('-', '_');
    client.createDatabase(database);

    table = "test";
    String insertJobId =
        client.submit(
            TDJobRequest.newPrestoQuery(database, "create table " + table + " as select 1"));

    TestUtils.expect(Duration.ofMinutes(5), jobSuccess(client, insertJobId));

    String selectCountJobId =
        client.submit(TDJobRequest.newPrestoQuery(database, "select count(*) from " + table));
    TestUtils.expect(Duration.ofMinutes(5), jobSuccess(client, selectCountJobId));

    List<ArrayNode> result = downloadResult(selectCountJobId);
    assertThat(result.get(0).get(0).asInt(), is(1));
  }
Esempio n. 13
0
 @Test
 public void genruleUsingBinaryUsingSharedLinkStyle() throws IOException {
   assumeThat(Platform.detect(), oneOf(Platform.LINUX, Platform.MACOS));
   ProjectWorkspace workspace =
       TestDataHelper.createProjectWorkspaceForScenario(this, "shared_link_style", tmp);
   workspace.setUp();
   workspace.runBuckBuild("//:gen").assertSuccess();
 }
Esempio n. 14
0
  @Before
  public void setUp() throws Exception {
    assumeThat(runEcho(), is(true));

    projectDir = folder.getRoot().toPath().toAbsolutePath().normalize();
    config = folder.newFile().toPath();
    outfile = projectDir.resolve("outfile");
  }
  @Test
  public void publishReceivedCountsEmptyMessages() {
    assumeThat(metricRegistry.getMeters().get("test.incompleteMessages").getCount(), is(0l));
    listener.publishReceived(client, new PublishMessage("test", QoS.AT_LEAST_ONCE, (byte[]) null));
    listener.publishReceived(client, new PublishMessage("test", QoS.AT_LEAST_ONCE, new byte[0]));

    assertThat(metricRegistry.getMeters().get("test.incompleteMessages").getCount(), is(2l));
  }
Esempio n. 16
0
  @Test
  public void nameIsTakenError() {
    String userName = getExistentName();
    Assume.assumeThat(userName, CoreMatchers.notNullValue());

    SignUpResultPage resultPage = signUpPage.signUp(userName, password, password, "", correctEmail);
    Assert.assertEquals(Source.getValue("SignUpErrorNameIsTakenError"), resultPage.getErrorText());
  }
 /**
  * Set up test fixtures.
  *
  * @throws Exception If some errors occurred.
  */
 @BeforeClass
 public static void setUp() throws Exception {
   final String key = System.getProperty("failsafe.github.key");
   Assume.assumeThat(key, Matchers.notNullValue());
   final Github github = new RtGithub(key);
   repos = github.repos();
   repo = rule.repo(repos);
 }
  @Test
  public void publishReceivedCountsDuplicateMessages() {
    final PublishMessage message = new PublishMessage("test", QoS.EXACTLY_ONCE, "test");

    assumeThat(metricRegistry.getMeters().get("test.incompleteMessages").getCount(), is(0l));
    listener.publishReceived(client, message);

    // assertThat(metricRegistry.getMeters().get("test.incompleteMessages").getCount(), is(1l));
  }
Esempio n. 19
0
 @Test
 public void buildBinaryWithPerFileFlags() throws IOException {
   assumeThat(Platform.detect(), is(Platform.MACOS));
   ProjectWorkspace workspace =
       TestDataHelper.createProjectWorkspaceForScenario(this, "per_file_flags", tmp);
   workspace.setUp();
   ProjectWorkspace.ProcessResult result = workspace.runBuckBuild("//:binary");
   result.assertSuccess();
 }
  @Theory
  public void nullValueReturnsNull(String value) {
    assumeThat(value, nullValue());

    component.setValue(value);

    Connection connection = converter.getConnection(facesEnv.getFacesContext(), component);
    assertThat(connection, nullValue());
  }
 @Override
 protected ConcurrentMap<Integer, byte[]> createOffHeapBufferMap(PageSource source) {
   assumeThat(generator, is(GOOD_GENERATOR));
   return new ReadWriteLockedOffHeapClockCache<Integer, byte[]>(
       source,
       new SplitStorageEngine<Integer, byte[]>(
           new IntegerStorageEngine(),
           new OffHeapBufferHalfStorageEngine<byte[]>(
               source, 1024, ByteArrayPortability.INSTANCE)));
 }
 @Test
 public void testCacheEviction() {
   assumeThat(generator, is(GOOD_GENERATOR));
   CapacityLimitedIntegerStorageEngineFactory factory =
       new CapacityLimitedIntegerStorageEngineFactory();
   CacheTestRoutines.testCacheEviction(
       new ReadWriteLockedOffHeapClockCache<Integer, Integer>(
           new UnlimitedPageSource(new OffHeapBufferSource()), factory.newInstance(), 1),
       factory);
 }
  @Theory
  @SuppressWarnings("unused")
  public void invalidDSThrowsSQLEx(String jndiName) {
    assumeThat(jndiName, notNullValue());
    assumeTrue(jndiName.startsWith("java:"));
    assumeThat(jndiName, containsString("invalid"));

    component.setValue(jndiName);

    Connection connection;
    try {
      connection = converter.getConnection(facesEnv.getFacesContext(), component);
      fail("A SQLException was expected");
    } catch (Exception e) {
      assumeThat(e, is(SourceException.class));
      assumeThat(e.getCause(), notNullValue());
      assumeThat(e.getCause(), is(SQLException.class));
    }
  }
Esempio n. 24
0
 @Theory
 public void testPlusFolding(RAbstractVector originalOperand) {
   RAbstractVector operand = originalOperand.copy();
   assumeThat(operand, is(not(instanceOf(RScalarVector.class))));
   if (operand.getRType() == getArgumentType(operand)) {
     assertFold(true, operand, PLUS);
   } else {
     assertFold(false, operand, PLUS);
   }
 }
  @Test
  public void testUnknownCharset() throws Exception {
    // We only want to run this test if we can guarantee that the charset _doesn't_ exist in the
    // system first. Otherwise, we'll just have to ignore this test.
    assumeThat(Charset.isSupported(UNKNOWN_CHARSET_NAME), is(false));

    // We're good to run the test.
    thrown.expect(ParameterException.class);
    thrown.expectMessage("unknown encoding");
    cc.convert(UNKNOWN_CHARSET_NAME);
  }
 /** Test to show assumptions using "org.junit.Assume.assumeThat()" method */
 @Test
 public void showAssumptionsUsingAssumeThat() {
   // Execute this test only if the assumption below is verified, if the
   // assumption is not verified the test being marked as passing,
   // regardless of what the code below the assumption may assert (the test code below assumption
   // is not executed).
   // Synthax is the same than the "org.junit.Assert.assertThat()" method
   Assume.assumeThat(System.getProperty("java.vm.vendor"), Is.is("Sun Microsystems Inc."));
   System.out.println(
       "showAssumptionsUsingAssumeThat() : Assumption verified then test code is executed !");
 }
Esempio n. 27
0
 @BeforeClass
 public static void setup() {
   System.err.println("java.vm.name:\t" + System.getProperty("java.vm.name", ""));
   System.err.println("java.vm.vendor:\t" + System.getProperty("java.vm.vendor", ""));
   assumeThat(System.getProperty("os.name"), not(containsString("AIX")));
   deepSizeOf(new CrossCheckingSizeOf(), null);
   System.err.println("JVM identified as: " + JvmInformation.CURRENT_JVM_INFORMATION);
   if (JvmInformation.CURRENT_JVM_INFORMATION == UNKNOWN_64_BIT
       || JvmInformation.CURRENT_JVM_INFORMATION == UNKNOWN_32_BIT) {
     System.getProperties().list(System.err);
   }
 }
 @Test
 public void testCacheEvictionDueToTableResizeFailure() {
   assumeThat(generator, is(GOOD_GENERATOR));
   for (int i = 1; i < 100; i++) {
     CacheTestRoutines.testCacheEvictionMinimal(
         new ReadWriteLockedOffHeapClockCache<Integer, Integer>(
             new PhantomReferenceLimitedPageSource(16 * i),
             new SplitStorageEngine<Integer, Integer>(
                 new IntegerStorageEngine(), new IntegerStorageEngine()),
             1));
   }
 }
Esempio n. 29
0
  /** Multi-thread read-write test. */
  @Test
  public void testReadWriteThreadsSurya() throws Exception {
    Assume.assumeThat(JvmInformation.isJRockit(), is(false));

    long start = System.currentTimeMillis();
    final List executables = new ArrayList();
    final Random random = new Random();

    // 50% of the time get data
    for (int i = 0; i < 10; i++) {
      final Executable executable =
          new Executable() {
            public void execute() throws Exception {
              store.get("key" + random.nextInt(10000));
            }
          };
      executables.add(executable);
    }

    // 25% of the time add data
    for (int i = 0; i < 5; i++) {
      final Executable executable =
          new Executable() {
            public void execute() throws Exception {
              store.put(new Element("key" + random.nextInt(20000), "value"));
            }
          };
      executables.add(executable);
    }

    // 25% if the time remove the data
    for (int i = 0; i < 5; i++) {
      final Executable executable =
          new Executable() {
            public void execute() throws Exception {
              store.remove("key" + random.nextInt(10000));
            }
          };
      executables.add(executable);
    }

    runThreads(executables);
    long end = System.currentTimeMillis();
    LOG.info("Total time for the test: " + (end + start) + " ms");
    tearDown();
    System.gc();
    System.gc();
    Thread.sleep(1000);
    System.gc();
    System.gc();
  }
Esempio n. 30
0
 @Test
 public void chromeProxyConfig() {
   assumeThat(System.getProperty("webdriver.chrome.driver"), is(notNullValue()));
   CrawlSession crawl =
       new BaseCrawler(Resource.newClassPathResource("/site"), "simplelink/simplelink.html") {
         @Override
         public CrawljaxConfigurationBuilder newCrawlConfigurationBuilder() {
           CrawljaxConfigurationBuilder builder = super.newCrawlConfigurationBuilder();
           builder.setBrowserConfig(new BrowserConfiguration(BrowserType.chrome));
           return builder;
         }
       }.crawl();
   assertThat(crawl.getStateFlowGraph(), hasStates(2));
 }