Skip to content

Commit

Permalink
Add caching properties to improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
seongahjo committed Sep 28, 2024
1 parent f508987 commit 355f304
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package com.navercorp.fixturemonkey.api.introspector;

import static com.navercorp.fixturemonkey.api.exception.Exceptions.throwAsUnchecked;
import static com.navercorp.fixturemonkey.api.property.DefaultPropertyGenerator.FIELD_PROPERTY_GENERATOR;
import static com.navercorp.fixturemonkey.api.property.DefaultPropertyGenerator.CACHED_DEFAULT_ANNOTATED_FIELD_PROPERTY_GENERATOR;

import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
Expand Down Expand Up @@ -122,6 +122,6 @@ private Function<Map<ArbitraryProperty, Object>, Object> combine(

@Override
public PropertyGenerator getRequiredPropertyGenerator(Property property) {
return FIELD_PROPERTY_GENERATOR;
return CACHED_DEFAULT_ANNOTATED_FIELD_PROPERTY_GENERATOR;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package com.navercorp.fixturemonkey.api.introspector;

import static com.navercorp.fixturemonkey.api.exception.Exceptions.throwAsUnchecked;
import static com.navercorp.fixturemonkey.api.property.DefaultPropertyGenerator.FIELD_PROPERTY_GENERATOR;
import static com.navercorp.fixturemonkey.api.property.DefaultPropertyGenerator.CACHED_DEFAULT_ANNOTATED_FIELD_PROPERTY_GENERATOR;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
Expand Down Expand Up @@ -126,6 +126,6 @@ private Function<Map<ArbitraryProperty, Object>, Object> combine(

@Override
public PropertyGenerator getRequiredPropertyGenerator(Property property) {
return FIELD_PROPERTY_GENERATOR;
return CACHED_DEFAULT_ANNOTATED_FIELD_PROPERTY_GENERATOR;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,43 @@

@API(since = "0.5.3", status = Status.MAINTAINED)
public final class DefaultPropertyGenerator implements PropertyGenerator {
public static final PropertyGenerator FIELD_PROPERTY_GENERATOR = new CompositePropertyGenerator(
Arrays.asList(
new FieldPropertyGenerator(
it -> true,
it -> true
),
new JavaBeansPropertyGenerator(
it -> it.getReadMethod() != null && it.getWriteMethod() != null,
it -> true
)
public static final PropertyGenerator CACHED_DEFAULT_FIELD_PROPERTY_GENERATOR = new LazyPropertyGenerator(
new FieldPropertyGenerator(
it -> true,
it -> true
)
);

private static final CompositePropertyGenerator COMPOSITE_PROPERTY_GENERATOR =
public static final PropertyGenerator CACHED_DEFAULT_JAVA_BEANS_PROPERTY_GENERATOR = new LazyPropertyGenerator(
new JavaBeansPropertyGenerator(
it -> it.getReadMethod() != null && it.getWriteMethod() != null,
it -> true
)
);

public static final PropertyGenerator CACHED_DEFAULT_CONSTRUCTOR_PROPERTY_GENERATOR =
new LazyPropertyGenerator(ConstructorPropertiesArbitraryIntrospector.PROPERTY_GENERATOR);

public static final PropertyGenerator CACHED_DEFAULT_ANNOTATED_FIELD_PROPERTY_GENERATOR = new LazyPropertyGenerator(
new CompositePropertyGenerator(
Arrays.asList(
ConstructorPropertiesArbitraryIntrospector.PROPERTY_GENERATOR,
FIELD_PROPERTY_GENERATOR
CACHED_DEFAULT_FIELD_PROPERTY_GENERATOR,
CACHED_DEFAULT_JAVA_BEANS_PROPERTY_GENERATOR
)
)
);

private static final PropertyGenerator CACHED_COMPOSITE_PROPERTY_GENERATOR =
new LazyPropertyGenerator(
new CompositePropertyGenerator(
Arrays.asList(
CACHED_DEFAULT_CONSTRUCTOR_PROPERTY_GENERATOR,
CACHED_DEFAULT_ANNOTATED_FIELD_PROPERTY_GENERATOR
)
)
);

public List<Property> generateChildProperties(Property property) {
return COMPOSITE_PROPERTY_GENERATOR.generateChildProperties(property);
return CACHED_COMPOSITE_PROPERTY_GENERATOR.generateChildProperties(property);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package com.navercorp.fixturemonkey.kotlin.property

import com.navercorp.fixturemonkey.api.container.ConcurrentLruCache
import com.navercorp.fixturemonkey.api.property.CompositeProperty
import com.navercorp.fixturemonkey.api.property.FieldPropertyGenerator
import com.navercorp.fixturemonkey.api.property.DefaultPropertyGenerator.CACHED_DEFAULT_FIELD_PROPERTY_GENERATOR
import com.navercorp.fixturemonkey.api.property.Property
import com.navercorp.fixturemonkey.api.property.PropertyGenerator
import org.apiguardian.api.API
Expand Down Expand Up @@ -66,6 +66,6 @@ internal class KotlinConstructorParameterPropertyGenerator(
}

companion object {
private val JAVA_FIELD_PROPERTY_GENERATOR = FieldPropertyGenerator({ true }) { true }
private val JAVA_FIELD_PROPERTY_GENERATOR = CACHED_DEFAULT_FIELD_PROPERTY_GENERATOR
}
}

0 comments on commit 355f304

Please sign in to comment.