Skip to content

Commit

Permalink
Adapted failing task-quartz-impl tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Nov 3, 2017
1 parent 8a2eb92 commit 7a5c404
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 51 deletions.
Expand Up @@ -683,7 +683,7 @@ public void startCollectingOperationStats(@NotNull StatisticsCollectionStrategy
}

@Override
public void storeOperationStatsTransient() {
public void storeOperationStatsDeferred() {

}

Expand Down
Expand Up @@ -1003,7 +1003,7 @@ void savePendingModifications(OperationResult parentResult) throws ObjectNotFoun

void startCollectingOperationStats(@NotNull StatisticsCollectionStrategy strategy);

void storeOperationStatsTransient();
void storeOperationStatsDeferred();

void storeOperationStats();

Expand Down
Expand Up @@ -298,12 +298,10 @@ public void setRecreateQuartzTrigger(boolean recreateQuartzTrigger) {
this.recreateQuartzTrigger = recreateQuartzTrigger;
}

private Collection<ItemDelta<?, ?>> pendingModifications = null;
@NotNull
private final Collection<ItemDelta<?, ?>> pendingModifications = new ArrayList<>();

public void addPendingModification(ItemDelta<?, ?> delta) {
if (pendingModifications == null) {
pendingModifications = new ArrayList<>();
}
ItemDelta.merge(pendingModifications, delta);
}

Expand Down Expand Up @@ -333,18 +331,19 @@ public void addModificationImmediate(ItemDelta<?, ?> delta, OperationResult pare
public void savePendingModifications(OperationResult parentResult)
throws ObjectNotFoundException, SchemaException, ObjectAlreadyExistsException {
if (isTransient()) {
synchronized (pendingModifications) {
pendingModifications.clear();
}
return;
}
if (pendingModifications != null) {
synchronized (pendingModifications) { // todo perhaps we should put something like this at more places here...
if (!pendingModifications.isEmpty()) {
synchronized (pendingModifications) { // todo perhaps we should put something like this at more places here...
if (!pendingModifications.isEmpty()) {

try {
repositoryService.modifyObject(TaskType.class, getOid(), pendingModifications, parentResult);
} finally { // todo reconsider this (it's not ideal but we need at least to reset pendingModifications to stop repeating applying this change)
synchronizeWithQuartzIfNeeded(pendingModifications, parentResult);
pendingModifications.clear();
}
try {
repositoryService.modifyObject(TaskType.class, getOid(), pendingModifications, parentResult);
} finally { // todo reconsider this (it's not ideal but we need at least to reset pendingModifications to stop repeating applying this change)
synchronizeWithQuartzIfNeeded(pendingModifications, parentResult);
pendingModifications.clear();
}
}
}
Expand All @@ -354,6 +353,7 @@ public void savePendingModifications(OperationResult parentResult)
}

@Override
@NotNull
public Collection<ItemDelta<?, ?>> getPendingModifications() {
return pendingModifications;
}
Expand All @@ -363,7 +363,7 @@ public void synchronizeWithQuartz(OperationResult parentResult) {
setRecreateQuartzTrigger(false);
}

private static Set<QName> quartzRelatedProperties = new HashSet<QName>();
private static Set<QName> quartzRelatedProperties = new HashSet<>();

static {
quartzRelatedProperties.add(TaskType.F_BINDING);
Expand Down Expand Up @@ -601,9 +601,8 @@ public void setResultStatusTypeTransient(OperationResultStatusType value) {
private PropertyDelta<?> setResultStatusTypeAndPrepareDelta(OperationResultStatusType value) {
setResultStatusTypeTransient(value);
if (isPersistent()) {
PropertyDelta<?> d = PropertyDelta.createReplaceDeltaOrEmptyDelta(taskManager.getTaskObjectDefinition(),
return PropertyDelta.createReplaceDeltaOrEmptyDelta(taskManager.getTaskObjectDefinition(),
TaskType.F_RESULT_STATUS, value);
return d;
} else {
return null;
}
Expand Down Expand Up @@ -731,7 +730,7 @@ public void pushHandlerUri(String uri, ScheduleType schedule, TaskBinding bindin
public void pushHandlerUri(String uri, ScheduleType schedule, TaskBinding binding, ItemDelta<?, ?> delta) {
Collection<ItemDelta<?, ?>> deltas = null;
if (delta != null) {
deltas = new ArrayList<ItemDelta<?, ?>>();
deltas = new ArrayList<>();
deltas.add(delta);
}
pushHandlerUri(uri, schedule, binding, deltas);
Expand Down Expand Up @@ -786,18 +785,15 @@ public void pushHandlerUri(String uri, ScheduleType schedule, TaskBinding bindin
public ItemDelta<?, ?> createExtensionDelta(PrismPropertyDefinition definition, Object realValue) {
PrismProperty<?> property = (PrismProperty<?>) definition.instantiate();
property.setRealValue(realValue);
PropertyDelta propertyDelta = PropertyDelta
.createModificationReplaceProperty(new ItemPath(TaskType.F_EXTENSION, property.getElementName()), definition,
realValue);
// PropertyDelta propertyDelta = new PropertyDelta(new ItemPath(TaskType.F_EXTENSION, property.getElementName()), definition);
// propertyDelta.setValuesToReplace(PrismValue.cloneCollection(property.getValues()));
return propertyDelta;
return PropertyDelta.createModificationReplaceProperty(new ItemPath(TaskType.F_EXTENSION, property.getElementName()), definition, realValue);
}

private void storeExtensionDeltas(List<ItemDeltaType> result, Collection<ItemDelta<?, ?>> extensionDeltas) {

for (ItemDelta itemDelta : extensionDeltas) {
Collection<ItemDeltaType> deltaTypes = null;
Collection<ItemDeltaType> deltaTypes;
try {
deltaTypes = DeltaConvertor.toItemDeltaTypes(itemDelta);
} catch (SchemaException e) {
Expand Down Expand Up @@ -916,7 +912,7 @@ public void checkDependencies(OperationResult result) throws SchemaException, Ob
if (!dependency.isClosed()) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Dependency {} of {} is not closed (status = {})",
new Object[] { dependency, this, dependency.getExecutionStatus() });
dependency, this, dependency.getExecutionStatus());
}
return;
}
Expand Down Expand Up @@ -1747,7 +1743,7 @@ public List<Task> listDependents(OperationResult parentResult) throws SchemaExce
result.addContext(OperationResult.CONTEXT_OID, getOid());
result.addContext(OperationResult.CONTEXT_IMPLEMENTATION_CLASS, TaskQuartzImpl.class);

List<Task> dependents = new ArrayList<Task>(getDependents().size());
List<Task> dependents = new ArrayList<>(getDependents().size());
for (String dependentId : getDependents()) {
try {
Task dependent = taskManager.getTaskByIdentifier(dependentId, result);
Expand Down Expand Up @@ -1898,9 +1894,9 @@ public <T> void setExtensionPropertyValue(QName propertyName, T value) throws Sc
throw new SchemaException("Unknown property " + propertyName);
}

ArrayList<PrismPropertyValue<T>> values = new ArrayList(1);
ArrayList<PrismPropertyValue<T>> values = new ArrayList<>(1);
if (value != null) {
values.add(new PrismPropertyValue<T>(value));
values.add(new PrismPropertyValue<>(value));
}
processModificationBatched(setExtensionPropertyAndPrepareDelta(propertyName, propertyDef, values));
}
Expand All @@ -1912,11 +1908,11 @@ public <T> void setExtensionPropertyValueTransient(QName propertyName, T value)
if (propertyDef == null) {
throw new SchemaException("Unknown property " + propertyName);
}
ArrayList<PrismPropertyValue<T>> values = new ArrayList(1);
ArrayList<PrismPropertyValue<T>> values = new ArrayList<>(1);
if (value != null) {
values.add(new PrismPropertyValue<T>(value));
values.add(new PrismPropertyValue<>(value));
}
ItemDelta delta = new PropertyDelta(new ItemPath(TaskType.F_EXTENSION, propertyName), propertyDef, getPrismContext());
ItemDelta delta = new PropertyDelta<>(new ItemPath(TaskType.F_EXTENSION, propertyName), propertyDef, getPrismContext());
delta.setValuesToReplace(values);

Collection<ItemDelta<?, ?>> modifications = new ArrayList<>(1);
Expand All @@ -1933,7 +1929,7 @@ public <T extends Containerable> void setExtensionContainerValue(QName container
throw new SchemaException("Unknown container item " + containerName);
}

ArrayList<PrismContainerValue<T>> values = new ArrayList(1);
ArrayList<PrismContainerValue<T>> values = new ArrayList<>(1);
values.add(value.asPrismContainerValue());
processModificationBatched(setExtensionContainerAndPrepareDelta(containerName, containerDef, values));
}
Expand Down Expand Up @@ -2024,7 +2020,7 @@ public void setExtensionPropertyImmediate(PrismProperty<?> property, OperationRe

private ItemDelta<?, ?> modifyExtensionAndPrepareDelta(ItemDelta<?, ?> delta) throws SchemaException {

Collection<ItemDelta<?, ?>> modifications = new ArrayList<ItemDelta<?, ?>>(1);
Collection<ItemDelta<?, ?>> modifications = new ArrayList<>(1);
modifications.add(delta);
PropertyDelta.applyTo(modifications, taskPrism); // i.e. here we apply changes only locally (in memory)

Expand All @@ -2033,7 +2029,7 @@ public void setExtensionPropertyImmediate(PrismProperty<?> property, OperationRe

private ItemDelta<?, ?> addExtensionPropertyAndPrepareDelta(QName itemName, PrismPropertyDefinition definition,
Collection<? extends PrismPropertyValue> values) throws SchemaException {
ItemDelta delta = new PropertyDelta(new ItemPath(TaskType.F_EXTENSION, itemName), definition, getPrismContext());
ItemDelta delta = new PropertyDelta<>(new ItemPath(TaskType.F_EXTENSION, itemName), definition, getPrismContext());

delta.addValuesToAdd(values);

Expand Down Expand Up @@ -2260,7 +2256,7 @@ private PropertyDelta<?> setNodeAndPrepareDelta(String value) {
@Override
public Long getLastRunStartTimestamp() {
XMLGregorianCalendar gc = taskPrism.asObjectable().getLastRunStartTimestamp();
return gc != null ? new Long(XmlTypeConverter.toMillis(gc)) : null;
return gc != null ? XmlTypeConverter.toMillis(gc) : null;
}

public void setLastRunStartTimestamp(Long value) {
Expand Down Expand Up @@ -2297,7 +2293,7 @@ private PropertyDelta<?> setLastRunStartTimestampAndPrepareDelta(Long value) {
@Override
public Long getLastRunFinishTimestamp() {
XMLGregorianCalendar gc = taskPrism.asObjectable().getLastRunFinishTimestamp();
return gc != null ? new Long(XmlTypeConverter.toMillis(gc)) : null;
return gc != null ? XmlTypeConverter.toMillis(gc) : null;
}

public void setLastRunFinishTimestamp(Long value) {
Expand Down Expand Up @@ -2334,7 +2330,7 @@ private PropertyDelta<?> setLastRunFinishTimestampAndPrepareDelta(Long value) {
@Override
public Long getCompletionTimestamp() {
XMLGregorianCalendar gc = taskPrism.asObjectable().getCompletionTimestamp();
return gc != null ? new Long(XmlTypeConverter.toMillis(gc)) : null;
return gc != null ? XmlTypeConverter.toMillis(gc) : null;
}

public void setCompletionTimestamp(Long value) {
Expand Down Expand Up @@ -2697,7 +2693,7 @@ public List<Task> listSubtasksDeeply(OperationResult parentResult) throws Schema
result.addContext(OperationResult.CONTEXT_OID, getOid());
result.addContext(OperationResult.CONTEXT_IMPLEMENTATION_CLASS, TaskQuartzImpl.class);

ArrayList<Task> retval = new ArrayList<Task>();
ArrayList<Task> retval = new ArrayList<>();
addSubtasks(retval, this, result);
return retval;
}
Expand Down Expand Up @@ -3099,14 +3095,14 @@ public void startCollectingOperationStats(@NotNull StatisticsCollectionStrategy
}

@Override
public void storeOperationStatsTransient() {
public void storeOperationStatsDeferred() {
setOperationStats(getAggregatedLiveOperationStats());
}

@Override
public void storeOperationStats() {
try {
storeOperationStatsTransient();
storeOperationStatsDeferred();
processModificationBatched(createProgressDelta(getProgress()));
processModificationBatched(createExpectedTotalDelta(getExpectedTotal()));
savePendingModifications(new OperationResult(DOT_INTERFACE + ".storeOperationStats")); // TODO fixme
Expand Down
Expand Up @@ -723,7 +723,7 @@ private boolean recordCycleRunFinish(TaskRunResult runResult, TaskHandler handle
}
}
task.setNode(null);
task.storeOperationStatsTransient();
task.storeOperationStatsDeferred();
task.savePendingModifications(result);

return true;
Expand Down
Expand Up @@ -91,7 +91,7 @@ public void testTasksCleanup() throws Exception {
// because now we can't move system time (we're not using DI for it) we create policy
// which should always point to 2013-05-07T12:00:00.000+02:00
final long NOW = System.currentTimeMillis();
Calendar when = create_2013_07_12_12_00_Calendar();
Calendar when = create_2013_05_07_12_00_00_Calendar();
CleanupPolicyType policy = createPolicy(when, NOW);

taskManager.cleanupTasks(policy, taskManager.createTaskInstance(), result);
Expand All @@ -114,7 +114,7 @@ public void testTasksCleanup() throws Exception {
AssertJUnit.assertTrue("finished: " + finished + ", mark: " + mark, finished.after(mark));
}

private Calendar create_2013_07_12_12_00_Calendar() {
private Calendar create_2013_05_07_12_00_00_Calendar() {
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT+2"));
calendar.set(Calendar.YEAR, 2013);
calendar.set(Calendar.MONTH, Calendar.MAY);
Expand Down
Expand Up @@ -28,7 +28,7 @@
<noop:delay xsi:type="xsd:int">500</noop:delay>
<noop:steps xsi:type="xsd:int">1</noop:steps>
</extension>
<taskIdentifier>10000000-0000-0000-0000-123450000013</taskIdentifier>
<taskIdentifier>91919191-76e0-59e2-86d6-556655660022</taskIdentifier>
<ownerRef oid="c0c010c0-d34d-b33f-f00d-111111111111"/>
<executionStatus>runnable</executionStatus>

Expand Down
Expand Up @@ -39,7 +39,7 @@
<description>
Definition of a live sychnronization task. It will poll changelog and pull in changes
</description>
<taskIdentifier>91919191-76e0-59e2-86d6-3d4f02d3ffff</taskIdentifier>
<taskIdentifier>1238546</taskIdentifier>
<ownerRef oid="00000000-0000-0000-0000-000000000002"/>
<executionStatus>runnable</executionStatus>

Expand All @@ -54,17 +54,17 @@

<task oid="1238546-1">
<name>OpenDJ1 child 1</name>
<taskIdentifier>91919191-76e0-59e2-86d6-3d4f02d3ffff-1</taskIdentifier>
<taskIdentifier>1238546-1</taskIdentifier>
<ownerRef oid="00000000-0000-0000-0000-000000000002"/>
<parent>91919191-76e0-59e2-86d6-3d4f02d3ffff</parent>
<parent>1238546</parent>
<completionTimestamp>2013-05-07T10:38:21.350+02:00</completionTimestamp>
</task>

<task oid="1238546-2">
<name>OpenDJ1 child 2</name>
<taskIdentifier>91919191-76e0-59e2-86d6-3d4f02d3ffff-2</taskIdentifier>
<taskIdentifier>1238546-2</taskIdentifier>
<ownerRef oid="00000000-0000-0000-0000-000000000002"/>
<parent>91919191-76e0-59e2-86d6-3d4f02d3ffff</parent>
<parent>1238546</parent>
<completionTimestamp>2013-05-07T10:38:21.350+02:00</completionTimestamp>
</task>

Expand All @@ -74,7 +74,7 @@
<description>
Definition of a live sychnronization task. It will poll changelog and pull in changes
</description>
<taskIdentifier>91919191-76e0-59e2-86d6-3d4f02d3ffff</taskIdentifier>
<taskIdentifier>1238547</taskIdentifier>
<ownerRef oid="00000000-0000-0000-0000-000000000002"/>
<executionStatus>runnable</executionStatus>

Expand All @@ -92,7 +92,7 @@
<description>
Definition of a live sychnronization task. It will poll changelog and pull in changes
</description>
<taskIdentifier>91919191-76e0-59e2-86d6-3d4f02d3ffff</taskIdentifier>
<taskIdentifier>1238548</taskIdentifier>
<ownerRef oid="00000000-0000-0000-0000-000000000002"/>
<executionStatus>runnable</executionStatus>

Expand Down

0 comments on commit 7a5c404

Please sign in to comment.