private static HazelcastInstanceImpl getHazelcastInstanceImpl(HazelcastInstance hz) { HazelcastInstanceImpl impl = null; if (hz instanceof HazelcastInstanceProxy) { return getFieldValue(hz, "original"); } else if (hz instanceof HazelcastInstanceImpl) { impl = (HazelcastInstanceImpl) hz; } return impl; }
public static Field getField(Class classType, String fieldName, Class fieldType) { Field field; do { field = findField(classType, fieldName, fieldType); if (field != null) { return field; } classType = classType.getSuperclass(); } while (classType != null); return null; }
public static void setFieldValue(Object instance, Field field, Object value) { field.setAccessible(true); setFieldValue0(instance, field, value); }
/** * Gets the value for a static field. * * @param clazz class which contains the field * @param fieldName name of the field * @param fieldType type of the field * @param <E> type of the field * @return the value of the static field */ public static <E> E getStaticFieldValue(Class clazz, String fieldName, Class fieldType) { Field field = getField(clazz, fieldName, fieldType); if (field == null) { throw new ReflectionException(format("Field %s.%s is not found", clazz.getName(), fieldName)); } field.setAccessible(true); return getFieldValue0(null, field, clazz.getName(), fieldName); }
public static <E> E getFieldValue(Object instance, String fieldName) { checkNotNull(instance, "Object to retrieve field from can't be null"); Field field; Class<?> clazz = instance.getClass(); try { field = clazz.getDeclaredField(fieldName); field.setAccessible(true); } catch (Exception e) { throw new ReflectionException(e); } return getFieldValue0(instance, field, clazz.getName(), fieldName); }
public static Field getFirstField(Class classType, Class<? extends Annotation> annotationClass) { List<Field> fields = getFields(classType, annotationClass); if (fields.isEmpty()) { return null; } return fields.get(0); }
private IWorker[] createWorkers() throws Exception { IWorker[] workers = new IWorker[threadCount]; for (int i = 0; i < threadCount; i++) { IWorker worker = invokeMethod(testInstance, runWithWorkersMethod); testContainer.getPropertyBinding().bind(worker); workers[i] = worker; } return workers; }
private void inject(Object object, Field field) { Class fieldType = field.getType(); if (field.isAnnotationPresent(InjectTestContext.class)) { assertFieldType(fieldType, TestContext.class, InjectTestContext.class); setFieldValue(object, field, testContext); } else if (field.isAnnotationPresent(InjectHazelcastInstance.class)) { assertFieldType(fieldType, HazelcastInstance.class, InjectHazelcastInstance.class); setFieldValue(object, field, testContext.getTargetInstance()); } else if (field.isAnnotationPresent(InjectProbe.class)) { assertFieldType(fieldType, Probe.class, InjectProbe.class); Probe probe = getOrCreateProbe(getProbeName(field), isPartOfTotalThroughput(field)); setFieldValue(object, field, probe); } else if (field.isAnnotationPresent(InjectMetronome.class)) { assertFieldType(fieldType, Metronome.class, InjectMetronome.class); Metronome metronome = workerMetronomeConstructor.newInstance(); setFieldValue(object, field, metronome); } }
void baseSetup() { this.map = targetInstance.getMap(name); this.operationCounter = targetInstance.getAtomicLong(name + "Ops"); this.exceptionCounter = targetInstance.getAtomicLong(name + "Exceptions"); Integer minResultSizeLimit = 100000; Float resultLimitFactor = 1.15f; try { Class queryResultSizeLimiterClazz = getQueryResultSizeLimiterClass(); minResultSizeLimit = getStaticFieldValue(queryResultSizeLimiterClazz, "MINIMUM_MAX_RESULT_LIMIT", int.class); resultLimitFactor = getStaticFieldValue(queryResultSizeLimiterClazz, "MAX_RESULT_LIMIT_FACTOR", float.class); } catch (Exception e) { logger.warning(format("%s: QueryResultSizeLimiter is not implemented in this Hazelcast version", name)); } int clusterSize = targetInstance.getCluster().getMembers().size(); this.globalKeyCount = getGlobalKeyCount(minResultSizeLimit, resultLimitFactor); this.localKeyCount = (int) Math.ceil(globalKeyCount / (double) clusterSize); logger.info(format("%s: Filling map with %d items (%d items per member, %d members in cluster)", name, globalKeyCount, localKeyCount, clusterSize)); }
/** * Gets the value for a static field. * * @param clazz class which contains the field * @param fieldName name of the field * @param fieldType type of the field * @param <E> type of the field * @return the value of the static field */ public static <E> E getStaticFieldValue(Class clazz, String fieldName, Class fieldType) { Field field = getField(clazz, fieldName, fieldType); if (field == null) { throw new ReflectionException(format("Field %s.%s is not found", clazz.getName(), fieldName)); } field.setAccessible(true); return getFieldValue0(null, field, clazz.getName(), fieldName); }
public static <E> E getFieldValue(Object instance, String fieldName) { checkNotNull(instance, "Object to retrieve field from can't be null"); Field field; Class<?> clazz = instance.getClass(); try { field = clazz.getDeclaredField(fieldName); field.setAccessible(true); } catch (Exception e) { throw new ReflectionException(e); } return getFieldValue0(instance, field, clazz.getName(), fieldName); }
private static HazelcastInstanceImpl getHazelcastInstanceImpl(HazelcastInstance hz) { HazelcastInstanceImpl impl = null; if (hz instanceof HazelcastInstanceProxy) { return getFieldValue(hz, "original"); } else if (hz instanceof HazelcastInstanceImpl) { impl = (HazelcastInstanceImpl) hz; } return impl; }
private static Object findTargetObject(Object parent, String property, String[] path) { for (int i = 0; i < path.length - 1; i++) { Class<?> clazz = parent.getClass(); String fieldName = path[i]; Field field = findField(clazz, fieldName); if (field == null) { if (i == 0) { // we have no match at all return null; } else { // we found at least one item in the path throw new BindException( format("Failed to find field [%s.%s] in property [%s]", clazz.getName(), fieldName, property)); } } Object child = getFieldValue0(parent, field, clazz.getName(), property); if (child == null) { try { child = field.getType().newInstance(); field.set(parent, child); } catch (InstantiationException e) { throw new BindException(format("Failed to initialize null field '%s'", field), e); } catch (IllegalAccessException e) { throw new BindException(format("Failed to initialize null field '%s'", field), e); } } parent = child; } return parent; }
public static Field getField(Class classType, String fieldName, Class fieldType) { Field field; do { field = findField(classType, fieldName, fieldType); if (field != null) { return field; } classType = classType.getSuperclass(); } while (classType != null); return null; }
public static void setFieldValue(Object instance, Field field, Object value) { field.setAccessible(true); setFieldValue0(instance, field, value); }
private static HazelcastInstanceImpl getHazelcastInstanceImpl(HazelcastInstance hz) { HazelcastInstanceImpl impl = null; if (hz instanceof HazelcastInstanceProxy) { return getFieldValue(hz, "original"); } else if (hz instanceof HazelcastInstanceImpl) { impl = (HazelcastInstanceImpl) hz; } return impl; }
@Verify public void verify() { if (isClient) { return; } long putCount = putCounter.get(); long getCount = getCounter.get(); Map<Integer, Object> slowOperationLogs = getFieldValue(slowOperationDetector, "slowOperationLogs"); int expected = (int) (Math.min(putCount, 1) + Math.min(getCount, 1)); long operationCount = putCount + getCount; logger.info(format("Expecting %d slow operation logs after completing %d operations (%d put, %d get).", expected, operationCount, putCount, getCount)); assertNotNull("Could not retrieve slow operation logs", slowOperationLogs); assertEqualsStringFormat("Expected %d slow operation logs, but was %d", expected, slowOperationLogs.size()); assertTrue("Expected at least one completed operations, but was " + operationCount + ". Please run the test for a longer time!", operationCount > 0); }
@Setup public void setUp() { isClient = isClient(targetInstance); keys = generateIntKeys(keyCount, KeyLocality.LOCAL, targetInstance); map = targetInstance.getMap(name); // try to find the slowOperationDetector instance (since Hazelcast 3.5) if (isMemberNode(targetInstance)) { slowOperationDetector = getFieldValue(getOperationService(targetInstance), "slowOperationDetector"); if (slowOperationDetector == null) { fail(name + ": This test needs Hazelcast 3.5 or newer"); } } }