Java Code Examples for org.apache.commons.lang.reflect.FieldUtils#getDeclaredField()

The following examples show how to use org.apache.commons.lang.reflect.FieldUtils#getDeclaredField() . 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: MqQueueExcutorServiceTest.java    From pmq with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 2
Source File: MqQueueExcutorServiceTest.java    From pmq with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 3
Source File: MqQueueExcutorServiceTest.java    From pmq with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 4
Source File: MqQueueExcutorServiceTest.java    From pmq with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 5
Source File: KNSLegacyDataAdapterImpl.java    From rice with Educational Community License v2.0 6 votes vote down vote up
/**
 * @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);
}
 
Example 6
Source File: MqQueueExcutorServiceTest.java    From pmq with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example 7
Source File: MqQueueExcutorServiceTest.java    From pmq with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 8
Source File: MqQueueExcutorServiceTest.java    From pmq with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 9
Source File: MqQueueExcutorServiceTest.java    From pmq with Apache License 2.0 5 votes vote down vote up
@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());
	}
 
Example 10
Source File: MqQueueExcutorServiceTest.java    From pmq with Apache License 2.0 5 votes vote down vote up
@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());
	}
 
Example 11
Source File: SFTPPutDialogTest.java    From hop with Apache License 2.0 4 votes vote down vote up
private static Field getPropsField() {
  return FieldUtils.getDeclaredField( Props.class, "props", true );
}
 
Example 12
Source File: TextFileInputDialogTest.java    From hop with Apache License 2.0 4 votes vote down vote up
private static Field getPropsField() {
  return FieldUtils.getDeclaredField( Props.class, "props", true );
}
 
Example 13
Source File: SFTPPutDialogTest.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
private static Field getPropsField() {
  return FieldUtils.getDeclaredField( Props.class, "props", true );
}
 
Example 14
Source File: TextFileInputDialogTest.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
private static Field getPropsField() {
  return FieldUtils.getDeclaredField( Props.class, "props", true );
}
 
Example 15
Source File: SalesforceInputDialogTest.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
private static Field getPropsField() {
  return FieldUtils.getDeclaredField( Props.class, "props", true );
}