Search in sources :

Example 1 with Property

use of com.pholser.junit.quickcheck.Property in project geode by apache.

the class BucketTargetingFixedResolverTest method shouldReturnCorrectPartitionForGetHashKey.

@Property
public void shouldReturnCorrectPartitionForGetHashKey(@Size(min = 1, max = 5) List<@InRange(minInt = 1, maxInt = 20) Integer> partitionSizes, @InRange(minInt = 0, maxInt = 50) int bucketId) {
    BucketTargetingFixedResolver resolver = new BucketTargetingFixedResolver();
    ConcurrentMap<String, Integer[]> fakePartitions = new ConcurrentHashMap<>();
    int startingBucket = 0;
    for (int i = 0; i < partitionSizes.size(); i++) {
        fakePartitions.put("p" + i, new Integer[] { startingBucket, partitionSizes.get(i) });
        startingBucket += partitionSizes.get(i);
    }
    assumeTrue(bucketId < startingBucket);
    final PartitionedRegion region = mock(PartitionedRegion.class);
    when(region.getPartitionsMap()).thenReturn(fakePartitions);
    when(region.isFixedPartitionedRegion()).thenReturn(true);
    when(region.getPartitionResolver()).thenReturn(resolver);
    assertEquals(bucketId, PartitionedRegionHelper.getHashKey(region, Operation.CREATE, "key", "value", bucketId));
}
Also used : PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Property(com.pholser.junit.quickcheck.Property)

Example 2 with Property

use of com.pholser.junit.quickcheck.Property in project geode by apache.

the class InternalDataSerializerQuickcheckStringTest method StringSerializedDeserializesToSameValue.

@Property(trials = 1000)
public void StringSerializedDeserializesToSameValue(String originalString) throws IOException {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream);
    DataSerializer.writeString(originalString, dataOutputStream);
    dataOutputStream.flush();
    byte[] stringBytes = byteArrayOutputStream.toByteArray();
    DataInputStream dataInputStream = new DataInputStream(new ByteArrayInputStream(stringBytes));
    String returnedString = DataSerializer.readString(dataInputStream);
    assertEquals("Deserialized string matches original", originalString, returnedString);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) Property(com.pholser.junit.quickcheck.Property)

Example 3 with Property

use of com.pholser.junit.quickcheck.Property in project grakn by graknlabs.

the class SchemaConceptPropertyTest method whenASchemaConceptHasAnIndirectSub_ItIsAnIndirectSuperOfThatSub.

@Property
public void whenASchemaConceptHasAnIndirectSub_ItIsAnIndirectSuperOfThatSub(@Open GraknTx tx, @FromTx SchemaConcept superConcept, long seed) {
    SchemaConcept subConcept = PropertyUtil.choose(superConcept.subs(), seed);
    assertThat(tx.admin().sups(subConcept).collect(toSet()), hasItem(superConcept));
}
Also used : SchemaConcept(ai.grakn.concept.SchemaConcept) Property(com.pholser.junit.quickcheck.Property)

Example 4 with Property

use of com.pholser.junit.quickcheck.Property in project grakn by graknlabs.

the class TypePropertyTest method whenDeletingAPlaysAndTheDirectSuperTypePlaysThatRole_TheTypeStillPlaysThatRole.

@Property
public void whenDeletingAPlaysAndTheDirectSuperTypePlaysThatRole_TheTypeStillPlaysThatRole(@NonMeta Type type, long seed) {
    Role role = PropertyUtil.choose(type.sup() + " plays no roles", type.sup().plays().collect(toSet()), seed);
    type.deletePlays(role);
    assertThat(type.plays().collect(toSet()), hasItem(role));
}
Also used : Role(ai.grakn.concept.Role) Property(com.pholser.junit.quickcheck.Property)

Example 5 with Property

use of com.pholser.junit.quickcheck.Property in project grakn by graknlabs.

the class AttributeTypePropertyTest method whenPuttingAResourceAndMethodThrows_DoNotCreateTheResource.

@Property
public void whenPuttingAResourceAndMethodThrows_DoNotCreateTheResource(@NonMeta @NonAbstract AttributeType type, @From(ResourceValues.class) Object value) {
    Collection previousResources = (Collection) type.instances().collect(toSet());
    try {
        type.putAttribute(value);
        assumeTrue("Assumed putResource would throw", false);
    } catch (GraknTxOperationException e) {
    // This is expected to throw
    }
    Collection newResources = (Collection) type.instances().collect(toSet());
    assertEquals(previousResources.size(), newResources.size());
}
Also used : Collection(java.util.Collection) GraknTxOperationException(ai.grakn.exception.GraknTxOperationException) Property(com.pholser.junit.quickcheck.Property)

Aggregations

Property (com.pholser.junit.quickcheck.Property)82 Matchers.hasProperty (org.hamcrest.Matchers.hasProperty)15 Program (com.rox.emu.processor.mos6502.util.Program)12 Role (ai.grakn.concept.Role)11 Label (ai.grakn.concept.Label)10 MetaSchema.isMetaLabel (ai.grakn.util.Schema.MetaSchema.isMetaLabel)10 Mos6502Compiler (com.rox.emu.processor.mos6502.util.Mos6502Compiler)10 SchemaConcept (ai.grakn.concept.SchemaConcept)9 RelationshipType (ai.grakn.concept.RelationshipType)8 AttributeType (ai.grakn.concept.AttributeType)7 VarProperty (ai.grakn.graql.admin.VarProperty)5 Ignore (org.junit.Ignore)5 Relationship (ai.grakn.concept.Relationship)4 Calendar (java.util.Calendar)4 Schema (org.apache.beam.sdk.schemas.Schema)4 ConceptId (ai.grakn.concept.ConceptId)3 Entity (ai.grakn.concept.Entity)3 EntityType (ai.grakn.concept.EntityType)3 Type (ai.grakn.concept.Type)3 VarPatternAdmin (ai.grakn.graql.admin.VarPatternAdmin)3