org.hamcrest.number.OrderingComparison Java Examples

The following examples show how to use org.hamcrest.number.OrderingComparison. 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: FBPreparedStatementTest.java    From jaybird with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testInsertReturning() throws Exception {
    executeCreateTable(con, CREATE_TEST_CHARS_TABLE);
    executeDDL(con, CREATE_GENERATOR);

    try (FirebirdPreparedStatement stmt = (FirebirdPreparedStatement) con
            .prepareStatement("INSERT INTO testtab(id, field1) VALUES(gen_id(test_generator, 1), 'a') RETURNING id")) {
        assertEquals(
                "TYPE_EXEC_PROCEDURE should be returned for an INSERT...RETURNING statement",
                FirebirdPreparedStatement.TYPE_EXEC_PROCEDURE,
                stmt.getStatementType());
        ResultSet rs = stmt.executeQuery();

        assertTrue("Should return at least 1 row", rs.next());
        assertThat("Generator value should be > 0", rs.getInt(1), OrderingComparison.greaterThan(0));
        assertFalse("Should return exactly one row", rs.next());
    }
}
 
Example #2
Source File: DockerComputerConnectorTest.java    From docker-plugin with MIT License 6 votes vote down vote up
@After
public void cleanup() throws Exception {
    terminateAllDockerNodes();
    final long startTimeMs = System.currentTimeMillis();
    final Long maxWaitTimeMs = 60 * 1000L;
    final long initialWaitTime = 50;
    long currentWaitTime = initialWaitTime;
    while( dockerIsStillBusy()) {
        currentWaitTime = currentWaitTime * 2;
        Thread.sleep(currentWaitTime);
        terminateAllDockerNodes();
        final long currentTimeMs = System.currentTimeMillis();
        final Long elapsedTimeMs = currentTimeMs - startTimeMs;
        Assert.assertThat(elapsedTimeMs, OrderingComparison.lessThan(maxWaitTimeMs));
    }
}
 
Example #3
Source File: MetadataIT.java    From apicurio-registry with Apache License 2.0 5 votes vote down vote up
@RegistryServiceTest(localOnly = false)
void getAndUpdateMetadataOfArtifact(RegistryService service) throws Exception {
    String artifactId = TestUtils.generateArtifactId();
    String artifactDefinition = "{\"type\":\"record\",\"name\":\"myrecord1\",\"fields\":[{\"name\":\"foo\",\"type\":\"string\"}]}";

    ByteArrayInputStream artifactData = new ByteArrayInputStream(artifactDefinition.getBytes(StandardCharsets.UTF_8));
    ArtifactMetaData metaData = ArtifactUtils.createArtifact(service, ArtifactType.AVRO, artifactId, artifactData);
    TestUtils.retry(() -> service.getArtifactMetaDataByGlobalId(metaData.getGlobalId()));
    LOGGER.info("Created artifact {} with metadata {}", artifactId, metaData);

    ArtifactMetaData artifactMetaData = service.getArtifactMetaData(artifactId);
    LOGGER.info("Got metadata of artifact with ID {}: {}", artifactId, artifactMetaData);

    assertThat(artifactMetaData.getCreatedOn(), OrderingComparison.greaterThan(0L));
    assertThat(artifactMetaData.getModifiedOn(), OrderingComparison.greaterThan(0L));
    assertThat(artifactMetaData.getId(), is(artifactId));
    assertThat(artifactMetaData.getVersion(), is(1));
    assertThat(artifactMetaData.getType().value(), is("AVRO"));

    EditableMetaData emd = new EditableMetaData();

    emd.setName("Artifact Updated Name");
    emd.setDescription("The description of the artifact.");

    service.updateArtifactMetaData(artifactId, emd);

    TestUtils.retry(() -> {
        ArtifactMetaData amd = service.getArtifactMetaData(artifactId);
        LOGGER.info("Got metadata of artifact with ID {}: {}", artifactId, amd);

        assertThat(amd.getId(), is(artifactId));
        assertThat(amd.getVersion(), is(1));
        assertThat(amd.getType().value(), is("AVRO"));
        assertThat(amd.getDescription(), is("The description of the artifact."));
        assertThat(amd.getName(), is("Artifact Updated Name"));
    });
}
 
Example #4
Source File: OAuth2TokenResponseTest.java    From cloud-security-xsuaa-integration with Apache License 2.0 5 votes vote down vote up
@Test
public void getExpiredDateFromAccessToken() {
	long expireInSeconds = 43199;
	Date minExpireDate = new Date(System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(expireInSeconds));
	OAuth2TokenResponse accessToken = new OAuth2TokenResponse("e9511922b5e64c49ba0eedcc8d772e76", expireInSeconds,
			null);
	Date maxExpireDate = new Date(System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(expireInSeconds));

	assertThat(accessToken.getExpiredAtDate(), allOf(OrderingComparison.greaterThanOrEqualTo(minExpireDate),
			OrderingComparison.lessThanOrEqualTo(maxExpireDate)));
}
 
Example #5
Source File: OAuth2TokenResponseTest.java    From cloud-security-xsuaa-integration with Apache License 2.0 5 votes vote down vote up
@Test
public void getExpiredFromAccessToken() {
	long expireInSeconds = 47299;
	Instant minExpireDate = getCurrentInstant().plusSeconds(expireInSeconds);

	OAuth2TokenResponse accessToken = new OAuth2TokenResponse(null, expireInSeconds, null);

	Instant maxExpireDate = getCurrentInstant().plusSeconds(expireInSeconds);

	assertThat(accessToken.getExpiredAt(), allOf(OrderingComparison.greaterThanOrEqualTo(minExpireDate),
			OrderingComparison.lessThanOrEqualTo(maxExpireDate)));
}
 
Example #6
Source File: UpfrontAllocatingPageSourceThresholdTest.java    From offheap-store with Apache License 2.0 5 votes vote down vote up
@Test
public void testThresholdsDuringSteal() {
  UpfrontAllocatingPageSource source = new UpfrontAllocatingPageSource(new HeapBufferSource(), MemoryUnit.KILOBYTES.toBytes(1), MemoryUnit.KILOBYTES.toBytes(1));
  SimpleOwner owner = new SimpleOwner();
  OffHeapStorageArea storage = new OffHeapStorageArea(PointerSize.INT, owner, source, 128, false, true);
  owner.bind(storage);

  final AtomicBoolean rising512 = new AtomicBoolean();
  source.addAllocationThreshold(ThresholdDirection.RISING, 512, () -> rising512.set(true));
  final AtomicBoolean falling64 = new AtomicBoolean();
  source.addAllocationThreshold(ThresholdDirection.FALLING, 64, () -> falling64.set(true));

  long victim = storage.allocate(128);
  assertThat(victim, OrderingComparison.greaterThanOrEqualTo(0L));
  assertThat(rising512.getAndSet(false), is(false));
  assertThat(falling64.getAndSet(false), is(false));

  Page thief = source.allocate(1024, true, false, null);
  assertThat(thief, IsNull.notNullValue());
  assertThat(storage.getAllocatedMemory(), is(0L));
  assertThat(rising512.getAndSet(false), is(true));
  assertThat(falling64.getAndSet(false), is(true));

  long fail = storage.allocate(128);
  assertThat(fail, is(-1L));
  assertThat(storage.getAllocatedMemory(), is(0L));
  assertThat(rising512.getAndSet(false), is(false));
  assertThat(falling64.getAndSet(false), is(false));

  source.free(thief);
  assertThat(storage.getAllocatedMemory(), is(0L));
  assertThat(source.getAllocatedSize(), is(0L));
  assertThat(rising512.getAndSet(false), is(false));
  assertThat(falling64.getAndSet(false), is(true));
}