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));
}
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);
}
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));
}
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));
}
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());
}
Aggregations