org.apache.commons.lang.reflect.FieldUtils#getDeclaredField ( )源码实例Demo

下面列出了org.apache.commons.lang.reflect.FieldUtils#getDeclaredField ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: pmq   文件: MqQueueExcutorServiceTest.java
@Test
public void testUpdateOffsetIdLess() throws NoSuchMethodException, SecurityException, IllegalAccessException,
		IllegalArgumentException, InvocationTargetException {

	MockMqClientBase mockMqClientBase = new MockMqClientBase();
	ConsumerQueueDto consumerQueueDto = buildDefaultConsumerQueueDto();
	consumerQueueDto.setPullBatchSize(100);
	MqQueueExcutorService mqQueueExcutorService = new MqQueueExcutorService(mockMqClientBase, consumerGroupName,
			consumerQueueDto);
	mqQueueExcutorService.updateQueueMeta(consumerQueueDto);

	consumerQueueDto = buildDefaultConsumerQueueDto();
	mqQueueExcutorService.updateOffset(consumerQueueDto, consumerQueueDto.getOffset() - 1);
	Field f = FieldUtils.getDeclaredField(MqQueueExcutorService.class, "consumerQueueRef", true);
	@SuppressWarnings("unchecked")
	AtomicReference<ConsumerQueueDto> consumerQueueRef = (AtomicReference<ConsumerQueueDto>) (f
			.get(mqQueueExcutorService));
	assertEquals("testUpdateOffsetIdLess error", consumerQueueRef.get().getOffset(), consumerQueueDto.getOffset());
}
 
源代码2 项目: pmq   文件: MqQueueExcutorServiceTest.java
@Test
public void testUpdateOffsetIdMore() throws NoSuchMethodException, SecurityException, IllegalAccessException,
		IllegalArgumentException, InvocationTargetException {

	MockMqClientBase mockMqClientBase = new MockMqClientBase();
	ConsumerQueueDto consumerQueueDto = buildDefaultConsumerQueueDto();
	consumerQueueDto.setPullBatchSize(100);
	MqQueueExcutorService mqQueueExcutorService = new MqQueueExcutorService(mockMqClientBase, consumerGroupName,
			consumerQueueDto);
	mqQueueExcutorService.updateQueueMeta(consumerQueueDto);

	consumerQueueDto = buildDefaultConsumerQueueDto();
	mqQueueExcutorService.updateOffset(consumerQueueDto, consumerQueueDto.getOffset() + 1);
	Field f = FieldUtils.getDeclaredField(MqQueueExcutorService.class, "consumerQueueRef", true);
	@SuppressWarnings("unchecked")
	AtomicReference<ConsumerQueueDto> consumerQueueRef = (AtomicReference<ConsumerQueueDto>) (f
			.get(mqQueueExcutorService));
	assertEquals("testUpdateOffsetIdLess error", consumerQueueRef.get().getOffset() + 1,
			consumerQueueDto.getOffset());
}
 
源代码3 项目: pmq   文件: MqQueueExcutorServiceTest.java
@Test
public void testUpdateLastIdLess() throws NoSuchMethodException, SecurityException, IllegalAccessException,
		IllegalArgumentException, InvocationTargetException {

	MockMqClientBase mockMqClientBase = new MockMqClientBase();
	ConsumerQueueDto consumerQueueDto = buildDefaultConsumerQueueDto();
	consumerQueueDto.setPullBatchSize(100);
	MqQueueExcutorService mqQueueExcutorService = new MqQueueExcutorService(mockMqClientBase, consumerGroupName,
			consumerQueueDto);
	mqQueueExcutorService.updateQueueMeta(consumerQueueDto);

	consumerQueueDto = buildDefaultConsumerQueueDto();
	MessageDto messageDto = new MessageDto();
	messageDto.setId(consumerQueueDto.getLastId() - 1);
	mqQueueExcutorService.updateLastId(consumerQueueDto, messageDto);
	Field f = FieldUtils.getDeclaredField(MqQueueExcutorService.class, "consumerQueueRef", true);
	@SuppressWarnings("unchecked")
	AtomicReference<ConsumerQueueDto> consumerQueueRef = (AtomicReference<ConsumerQueueDto>) (f
			.get(mqQueueExcutorService));
	assertEquals("testUpdateLastIdLess error", consumerQueueRef.get().getLastId(), consumerQueueDto.getOffset());
}
 
源代码4 项目: pmq   文件: MqQueueExcutorServiceTest.java
@Test
public void testUpdateLastIdMore() throws NoSuchMethodException, SecurityException, IllegalAccessException,
		IllegalArgumentException, InvocationTargetException {
	MockMqClientBase mockMqClientBase = new MockMqClientBase();
	ConsumerQueueDto consumerQueueDto = buildDefaultConsumerQueueDto();
	consumerQueueDto.setPullBatchSize(100);
	MqQueueExcutorService mqQueueExcutorService = new MqQueueExcutorService(mockMqClientBase, consumerGroupName,
			consumerQueueDto);

	mqQueueExcutorService.updateQueueMeta(consumerQueueDto);

	consumerQueueDto = buildDefaultConsumerQueueDto();
	MessageDto messageDto = new MessageDto();
	messageDto.setId(consumerQueueDto.getOffset() + 1);
	mqQueueExcutorService.updateLastId(consumerQueueDto, messageDto);
	Field f = FieldUtils.getDeclaredField(MqQueueExcutorService.class, "consumerQueueRef", true);
	@SuppressWarnings("unchecked")
	AtomicReference<ConsumerQueueDto> consumerQueueRef = (AtomicReference<ConsumerQueueDto>) (f
			.get(mqQueueExcutorService));
	assertEquals("testUpdateLastIdMore error", consumerQueueRef.get().getLastId() + 1,
			consumerQueueDto.getLastId());
}
 
源代码5 项目: rice   文件: KNSLegacyDataAdapterImpl.java
/**
 * @see ValueHolderFieldPair for information on why we need to do field sychronization related to weaving
 */
private void searchValueHolderFieldPairs(Class<?> type, List<ValueHolderFieldPair> pairs) {
    if (type.equals(Object.class)) {
        return;
    }
    for (Field valueHolderField : type.getDeclaredFields()) {
        Matcher matcher = VALUE_HOLDER_FIELD_PATTERN.matcher(valueHolderField.getName());
        if (matcher.matches()) {
            valueHolderField.setAccessible(true);
            String fieldName = matcher.group(1);
            Field valueField = FieldUtils.getDeclaredField(type, fieldName, true);
            if (valueField != null) {
                pairs.add(new ValueHolderFieldPair(valueField, valueHolderField));
            }
        }
    }
    searchValueHolderFieldPairs(type.getSuperclass(), pairs);
}
 
源代码6 项目: pmq   文件: MqQueueExcutorServiceTest.java
@Test
public void testConstruct() throws IllegalArgumentException, IllegalAccessException {
	MockMqClientBase mockMqClientBase = new MockMqClientBase();
	MqQueueExcutorService mqQueueExcutorService = new MqQueueExcutorService(mockMqClientBase, consumerGroupName,
			buildDefaultConsumerQueueDto());
	Field f = FieldUtils.getDeclaredField(MqQueueExcutorService.class, "executor", true);
	assertNotEquals("executor construct error", null, f.get(mqQueueExcutorService));

	f = FieldUtils.getDeclaredField(MqQueueExcutorService.class, "iSubscriber", true);
	assertNotEquals("iSubscriber construct error", null, f.get(mqQueueExcutorService));

	f = FieldUtils.getDeclaredField(MqQueueExcutorService.class, "mqResource", true);
	assertNotEquals("mqResource construct error", null, f.get(mqQueueExcutorService));
}
 
源代码7 项目: pmq   文件: MqQueueExcutorServiceTest.java
@Test
public void testThreadSize() throws IllegalArgumentException, IllegalAccessException {
	MockMqClientBase mockMqClientBase = new MockMqClientBase();
	MqQueueExcutorService mqQueueExcutorService = new MqQueueExcutorService(mockMqClientBase, consumerGroupName,
			buildDefaultConsumerQueueDto());
	ConsumerQueueDto consumerQueueDto = buildDefaultConsumerQueueDto();
	consumerQueueDto.setThreadSize(consumerQueueDto.getThreadSize() + 1);
	mqQueueExcutorService.updateQueueMeta(consumerQueueDto);
	Field f = FieldUtils.getDeclaredField(MqQueueExcutorService.class, "consumerQueueRef", true);
	@SuppressWarnings("unchecked")
	AtomicReference<ConsumerQueueDto> consumerQueueRef = (AtomicReference<ConsumerQueueDto>) (f
			.get(mqQueueExcutorService));
	assertEquals("threadSize error", consumerQueueDto.getThreadSize(), consumerQueueRef.get().getThreadSize());
}
 
源代码8 项目: pmq   文件: MqQueueExcutorServiceTest.java
@Test
public void testQueueOffsetVersion() throws IllegalArgumentException, IllegalAccessException {
	MockMqClientBase mockMqClientBase = new MockMqClientBase();
	MqQueueExcutorService mqQueueExcutorService = new MqQueueExcutorService(mockMqClientBase, consumerGroupName,
			buildDefaultConsumerQueueDto());
	ConsumerQueueDto consumerQueueDto = buildDefaultConsumerQueueDto();
	consumerQueueDto.setOffsetVersion(consumerQueueDto.getOffsetVersion() + 1);
	mqQueueExcutorService.updateQueueMeta(consumerQueueDto);
	Field f = FieldUtils.getDeclaredField(MqQueueExcutorService.class, "consumerQueueRef", true);
	@SuppressWarnings("unchecked")
	AtomicReference<ConsumerQueueDto> consumerQueueRef = (AtomicReference<ConsumerQueueDto>) (f
			.get(mqQueueExcutorService));
	assertEquals("OffsetVersion error", consumerQueueDto.getOffset(), consumerQueueRef.get().getLastId());
}
 
源代码9 项目: pmq   文件: MqQueueExcutorServiceTest.java
@Test
	public void testDoPullingDataNotFull() throws IllegalArgumentException, IllegalAccessException,
			NoSuchMethodException, SecurityException, InvocationTargetException {
		MockMqClientBase mockMqClientBase = new MockMqClientBase();
		MqQueueExcutorService mqQueueExcutorService = new MqQueueExcutorService(mockMqClientBase, consumerGroupName,
				buildDefaultConsumerQueueDto());

		// MqQueueResource resource = (MqQueueResource)
		// mockMqClientBase.getContext().getMqResource();
		ConsumerQueueDto consumerQueueDto = buildDefaultConsumerQueueDto();
		consumerQueueDto.setStopFlag(0);
		mqQueueExcutorService.updateQueueMeta(consumerQueueDto);

//		Method doPullingData = MqQueueExcutorService.class.getDeclaredMethod("doPullingData");
//		doPullingData.setAccessible(true);
//		doPullingData.invoke(mqQueueExcutorService);
		mqQueueExcutorService.doPullingData();

		Field f = FieldUtils.getDeclaredField(MqQueueExcutorService.class, "messages", true);
		@SuppressWarnings("unchecked")
		BlockingQueue<MessageDto> messages = (BlockingQueue<MessageDto>) (f.get(mqQueueExcutorService));
		assertEquals("testDoPullingDataNotFull 1 error", 1, messages.size());

		// doPullingData.invoke(mqQueueExcutorService);
		mqQueueExcutorService.doPullingData();
		assertEquals("testDoPullingDataNotFull 2 error", 2, messages.size());
	}
 
源代码10 项目: pmq   文件: MqQueueExcutorServiceTest.java
@Test
	public void testDoPullingDataFull() throws IllegalArgumentException, IllegalAccessException, NoSuchMethodException,
			SecurityException, InvocationTargetException {
		MockMqClientBase mockMqClientBase = new MockMqClientBase();
		MqQueueExcutorService mqQueueExcutorService = new MqQueueExcutorService(mockMqClientBase, consumerGroupName,
				buildDefaultConsumerQueueDto());

		// MqQueueResource resource = (MqQueueResource)
		// mockMqClientBase.getContext().getMqResource();
		ConsumerQueueDto consumerQueueDto = buildDefaultConsumerQueueDto();
		consumerQueueDto.setStopFlag(0);
		consumerQueueDto.setPullBatchSize(301);
		mqQueueExcutorService.updateQueueMeta(consumerQueueDto);

//		Method doPullingData = MqQueueExcutorService.class.getDeclaredMethod("doPullingData");
//		doPullingData.setAccessible(true);
		Runnable runnable = new Runnable() {
			@Override
			public void run() {
//					doPullingData.invoke(mqQueueExcutorService);
				mqQueueExcutorService.doPullingData();

			}
		};

		ExecutorService executorService = Executors.newSingleThreadExecutor();
		executorService.submit(runnable);
		Util.sleep(2000);
		Field f = FieldUtils.getDeclaredField(MqQueueExcutorService.class, "messages", true);
		@SuppressWarnings("unchecked")
		BlockingQueue<MessageDto> messages = (BlockingQueue<MessageDto>) (f.get(mqQueueExcutorService));
		assertEquals("testDoPullingDataFull 300 error", 300, messages.size());
		for (int i = 0; i < 300; i++) {
			messages.poll();
		}
		Util.sleep(2000);
		assertEquals("testDoPullingDataFull 1 error", 1, messages.size());
	}
 
源代码11 项目: hop   文件: SFTPPutDialogTest.java
private static Field getPropsField() {
  return FieldUtils.getDeclaredField( Props.class, "props", true );
}
 
源代码12 项目: hop   文件: TextFileInputDialogTest.java
private static Field getPropsField() {
  return FieldUtils.getDeclaredField( Props.class, "props", true );
}
 
源代码13 项目: pentaho-kettle   文件: SFTPPutDialogTest.java
private static Field getPropsField() {
  return FieldUtils.getDeclaredField( Props.class, "props", true );
}
 
源代码14 项目: pentaho-kettle   文件: TextFileInputDialogTest.java
private static Field getPropsField() {
  return FieldUtils.getDeclaredField( Props.class, "props", true );
}
 
源代码15 项目: pentaho-kettle   文件: SalesforceInputDialogTest.java
private static Field getPropsField() {
  return FieldUtils.getDeclaredField( Props.class, "props", true );
}