Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleaner integration tests #489

Merged
merged 70 commits into from
Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from 68 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
69689ea
Add base embedded mongo test
Feb 26, 2019
a6901f1
Change fake server to "mongo-java-server"
Feb 27, 2019
99621e7
Remove comment
Feb 27, 2019
de814c7
Code cleanup
Feb 27, 2019
f2e85b4
Add mock dependency
Feb 27, 2019
2c01a09
Cleanup pom
Feb 27, 2019
e1fc3f2
Add needed dependencies for mocking OSGI
Feb 27, 2019
47cb57a
Add registering services with mocked mongoUri
Feb 27, 2019
33c2305
Clean code
Feb 27, 2019
3fbf382
Rename + move test class
Feb 28, 2019
02f1c9a
Add registering all processors
Feb 28, 2019
bdcb9ac
Add starting clener job in test
Feb 28, 2019
e612a40
Remove junk code
Feb 28, 2019
70bdd05
Extract jobDetails setup function
Feb 28, 2019
a4d5ec6
Cleanup code
Feb 28, 2019
85c8e44
Remove unused imports
Feb 28, 2019
79d463c
Separate server socket binding from creating mongoUri
Feb 28, 2019
68a7070
Add test in json file
Feb 28, 2019
f0fa2e6
Change structure
Feb 28, 2019
95ff93a
Add inserting all collections to db
Feb 28, 2019
65d5da9
Separate db names and filesystem paths
Feb 28, 2019
e2a0062
Merge branch 'master' into feature/cleaner-integration-test
Feb 28, 2019
80490bc
Add first test
Feb 28, 2019
e91f13b
Change suite version
Feb 28, 2019
98ceeb7
Add localDateTimeProvider interface to facilitate testing
Mar 1, 2019
e76ea13
Add second suite
Mar 1, 2019
5a02e1f
Add mocked current datetime for testing
Mar 1, 2019
919db96
Switch to ZohhakRunner
Mar 1, 2019
9879302
Change timestamps
Mar 1, 2019
73600d8
Fix suite version
Mar 1, 2019
b193afe
Add first tests
Mar 1, 2019
8834a69
Refactoring
Mar 1, 2019
2013f1d
Add test for all tests younger
Mar 1, 2019
0dfc517
Refactoring
Mar 1, 2019
66f13bb
Remove chunks (mongoDB deletes them ootb with file doc)
Mar 1, 2019
954900d
Add checking for artifacts
Mar 1, 2019
86e59d8
Add test case for removing all
Mar 1, 2019
7734bf7
Rename methods
Mar 1, 2019
2b06e6b
Remove redundant test cases
Mar 1, 2019
baddf15
Add more test files
Mar 5, 2019
79383f4
Fix test cases
Mar 5, 2019
d2cf95e
Change test files to "AET in 10 minutes" example
Mar 5, 2019
8c274bc
Add some rebased test file
Mar 5, 2019
63076ad
Fix chronological order
Mar 5, 2019
1206ebf
Add more detailed timestamp comment
Mar 5, 2019
b55c341
Fix test case (removing is inclusive)
Mar 5, 2019
f0c791a
Add second test files (two tests in one suite)
Mar 5, 2019
2312bef
Add tests for second suite
Mar 5, 2019
cf6dc72
Fix keeping newest test
Mar 5, 2019
e2e5355
Add tests for projectB
Mar 5, 2019
378ec59
Add injecting camelContextCreator for test purposes
Mar 7, 2019
85c4534
Rename tests
Mar 7, 2019
994f436
Add test with specific ids check
Mar 7, 2019
b941257
Refactor (extract db-related stuff to separate class)
Mar 7, 2019
c174fe8
Add missing license
Mar 7, 2019
e437559
Update changelog
Mar 7, 2019
673df35
Merge branch 'master' into feature/cleaner-integration-test
wblachowski Mar 7, 2019
c0537b8
Add system local datetime provider
wblachowski Mar 7, 2019
719c0e4
Add test scopes in dependencyManagement
Mar 12, 2019
8a2b59d
Merge remote-tracking branch 'origin/feature/cleaner-integration-test…
Mar 12, 2019
3132598
Merge branch 'master' into feature/cleaner-integration-test
Mar 19, 2019
34c273f
Merge branch 'master' of https://github.com/Cognifide/aet into featur…
tkaik May 27, 2019
8a61aa9
Merge branch 'master' of https://github.com/Cognifide/aet into featur…
tkaik Jul 3, 2019
27e9a5f
CHANGELOG entry moved to Unrelease section
tkaik Jul 3, 2019
c735c3c
maven-bundle-plugin config and osgi-mock dependencyMgmt moved to root…
tkaik Jul 3, 2019
095158b
methods order in CleanerIntegrationTest
tkaik Jul 3, 2019
b53a26c
Cleaner integration tests in seperate maven module under integration-…
tkaik Jul 4, 2019
24c45bc
cleaner/cleaner-test dependencies cleanup
tkaik Jul 4, 2019
cd8852d
move all code in clenaer-test module to src/test/java
tkaik Jul 8, 2019
2f6bb98
Merge branch 'master' into feature/cleaner-integration-test
tkaik Jul 12, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ All notable changes to AET will be documented in this file.
## Unreleased

**List of changes that are finished but not yet released in any final version.**
- [PR-489](https://github.com/Cognifide/aet/pull/489) Cleaner integration tests

## Version 3.2.2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
package com.cognifide.aet.cleaner;


import com.cognifide.aet.cleaner.camel.CamelContextCreator;
import com.cognifide.aet.cleaner.context.CleanerContext;
import com.cognifide.aet.cleaner.route.MetadataCleanerRouteBuilder;
import org.apache.camel.CamelContext;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.impl.DefaultCamelContext;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
Expand All @@ -46,6 +46,8 @@ public class CleanerJob implements Job {

static final String KEY_DRY_RUN = "dryRun";

static final String KEY_CAMEL_CONTEXT_CREATOR = "camelContextCreator";

@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
CamelContext camelContext = null;
Expand All @@ -59,8 +61,10 @@ public void execute(JobExecutionContext context) throws JobExecutionException {
final String companyFilter = (String) jobDataMap.get(KEY_COMPANY_FILTER);
final String projectFilter = (String) jobDataMap.get(KEY_PROJECT_FILTER);
final Boolean dryRun = (Boolean) jobDataMap.get(KEY_DRY_RUN);
final CamelContextCreator contextCreator = (CamelContextCreator) jobDataMap
.get(KEY_CAMEL_CONTEXT_CREATOR);

camelContext = new DefaultCamelContext();
camelContext = contextCreator.create();
camelContext.setAllowUseOriginalMessage(false);
camelContext.addRoutes(cleanerRouteBuilder);
camelContext.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.cognifide.aet.cleaner;

import com.cognifide.aet.cleaner.camel.CamelContextCreator;
import com.cognifide.aet.cleaner.configuration.CleanerSchedulerConf;
import com.cognifide.aet.cleaner.route.MetadataCleanerRouteBuilder;
import com.cognifide.aet.cleaner.validation.CleanerSchedulerValidator;
Expand Down Expand Up @@ -58,6 +59,9 @@ public class CleanerScheduler {
@Reference
private MetadataCleanerRouteBuilder metadataCleanerRouteBuilder;

@Reference
private CamelContextCreator camelContextCreator;

@Reference
private ValidationResultBuilderFactory validationResultBuilderFactory;

Expand Down Expand Up @@ -118,6 +122,7 @@ private String registerCleaningJob() throws SchedulerException {

final ImmutableMap<String, Object> jobData = ImmutableMap.<String, Object>builder()
.put(CleanerJob.KEY_ROUTE_BUILDER, metadataCleanerRouteBuilder)
.put(CleanerJob.KEY_CAMEL_CONTEXT_CREATOR, camelContextCreator)
.put(CleanerJob.KEY_KEEP_N_VERSIONS, config.keepNVersions())
.put(CleanerJob.KEY_REMOVE_OLDER_THAN, config.removeOlderThan())
.put(CleanerJob.KEY_COMPANY_FILTER, config.companyName())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* AET
*
* Copyright (C) 2013 Cognifide Limited
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package com.cognifide.aet.cleaner.camel;

import org.apache.camel.CamelContext;

public interface CamelContextCreator {

CamelContext create();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* AET
*
* Copyright (C) 2013 Cognifide Limited
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package com.cognifide.aet.cleaner.camel;

import org.apache.camel.CamelContext;
import org.apache.camel.impl.DefaultCamelContext;
import org.osgi.service.component.annotations.Component;

@Component(service = CamelContextCreator.class)
public class DefaultCamelContextCreator implements CamelContextCreator {

@Override
public CamelContext create() {
return new DefaultCamelContext();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.cognifide.aet.cleaner.processors.exchange.AllSuiteVersionsMessageBody;
import com.cognifide.aet.cleaner.processors.exchange.SuiteMessageBody;
import com.cognifide.aet.cleaner.processors.filters.SuiteRemoveCondition;
import com.cognifide.aet.cleaner.time.LocalDateTimeProvider;
import com.cognifide.aet.communication.api.metadata.Suite;
import com.cognifide.aet.vs.DBKey;
import com.google.common.base.Function;
Expand All @@ -29,6 +30,7 @@
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -38,6 +40,9 @@ public class SuitesRemovePredicateProcessor implements Processor {
private static final Logger LOGGER = LoggerFactory
.getLogger(SuitesRemovePredicateProcessor.class);

@Reference
private LocalDateTimeProvider dateTimeProvider;

@Override
@SuppressWarnings("unchecked")
public void process(Exchange exchange) throws Exception {
Expand All @@ -53,7 +58,7 @@ public void process(Exchange exchange) throws Exception {
suiteVersions.size(), dbKey);

final SuiteRemoveCondition removeCondition = new SuiteRemoveCondition(suiteVersions,
cleanerContext);
cleanerContext, dateTimeProvider);

final ImmutableList<SuiteMessageBody> body =
FluentIterable.from(suiteVersions).transform(new Function<Suite, SuiteMessageBody>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.cognifide.aet.cleaner.processors.filters;

import com.cognifide.aet.cleaner.context.CleanerContext;
import com.cognifide.aet.cleaner.time.LocalDateTimeProvider;
import com.cognifide.aet.communication.api.metadata.Suite;
import com.google.common.collect.Ordering;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -45,9 +46,9 @@ public int compare(Suite o1, Suite o2) {
private final Long minKeepVersion;

public SuiteRemoveCondition(final Collection<Suite> suiteRunVersions,
final CleanerContext cleanerContext) {
final CleanerContext cleanerContext, LocalDateTimeProvider dateTimeProvider) {
minKeepVersion = getMinKeepVersion(suiteRunVersions, cleanerContext);
removeTimestamp = getRemoveTimestamp(cleanerContext);
removeTimestamp = getRemoveTimestamp(cleanerContext, dateTimeProvider);
}

public boolean evaluate(final Suite suite) {
Expand Down Expand Up @@ -86,10 +87,10 @@ private Long getMinKeepVersion(final Collection<Suite> suiteRunVersions,
return minVersionToKeep;
}

private Long getRemoveTimestamp(CleanerContext cleanerContext) {
private Long getRemoveTimestamp(CleanerContext cleanerContext, LocalDateTimeProvider dateTimeProvider) {
Long removeBeforeTimestamp = null;
if (cleanerContext.getRemoveOlderThan() != null) {
LocalDateTime now = LocalDateTime.now(ZoneOffset.UTC);
LocalDateTime now = dateTimeProvider.now(ZoneOffset.UTC);
int daysToKeep = cleanerContext.getRemoveOlderThan().intValue();
LocalDateTime then = now.minusDays(daysToKeep);
removeBeforeTimestamp = then.toInstant(ZoneOffset.UTC).toEpochMilli();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* AET
*
* Copyright (C) 2013 Cognifide Limited
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package com.cognifide.aet.cleaner.time;

import java.time.LocalDateTime;
import java.time.ZoneId;

public interface LocalDateTimeProvider {

LocalDateTime now(ZoneId zone);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* AET
*
* Copyright (C) 2013 Cognifide Limited
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package com.cognifide.aet.cleaner.time;

import java.time.LocalDateTime;
import java.time.ZoneId;
import org.osgi.service.component.annotations.Component;

@Component(service = LocalDateTimeProvider.class)
public class SystemLocalDateTime implements LocalDateTimeProvider {

@Override
public LocalDateTime now(ZoneId zone) {
return LocalDateTime.now(zone);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.mockito.Mockito.when;

import com.cognifide.aet.cleaner.context.CleanerContext;
import com.cognifide.aet.cleaner.time.SystemLocalDateTime;
import com.cognifide.aet.communication.api.metadata.Suite;
import com.cognifide.aet.communication.api.metadata.Suite.Timestamp;
import com.googlecode.zohhak.api.Configure;
Expand Down Expand Up @@ -52,7 +53,7 @@ public void evaluate_whenOnlyOneSuite_expectFalseNoMatterConditions(String allSu

Suite suite = mockSuiteVersionAndCreatedDate(evaluatedSuite, createdDaysAgo);
SuiteRemoveCondition condition = new SuiteRemoveCondition(suites,
mockRemoveConditions(removeOlderThan, keepNVersions));
mockRemoveConditions(removeOlderThan, keepNVersions), new SystemLocalDateTime());
final boolean remove = condition.evaluate(suite);
assertFalse(remove);
}
Expand Down Expand Up @@ -82,7 +83,7 @@ public void evaluate_when8SuitesVersionsRemoveOldVersions_expectTrue(String allS

Suite suite = mockSuiteVersionAndCreatedDate(evaluatedSuite, createdDaysAgo);
SuiteRemoveCondition condition = new SuiteRemoveCondition(suites,
mockRemoveConditions(removeOlderThan, keepNVersions));
mockRemoveConditions(removeOlderThan, keepNVersions), new SystemLocalDateTime());
final boolean remove = condition.evaluate(suite);
assertTrue(remove);
}
Expand All @@ -108,7 +109,7 @@ public void evaluate_when8SuitesVersionsKeepLastVersions_expectFalse(String allS

Suite suite = mockSuiteVersionAndCreatedDate(evaluatedSuite, createdDaysAgo);
SuiteRemoveCondition condition = new SuiteRemoveCondition(suites,
mockRemoveConditions(removeOlderThan, keepNVersions));
mockRemoveConditions(removeOlderThan, keepNVersions), new SystemLocalDateTime());
final boolean remove = condition.evaluate(suite);
assertFalse(remove);
}
Expand Down Expand Up @@ -136,7 +137,7 @@ public void evaluate_when8SuitesRemoveOlderThanButAlwaysKeepLatestVersion_expect

Suite suite = mockSuiteVersionAndCreatedDate(evaluatedSuite, createdDaysAgo);
SuiteRemoveCondition condition = new SuiteRemoveCondition(suites,
mockRemoveConditions(removeOlderThan, keepNVersions));
mockRemoveConditions(removeOlderThan, keepNVersions), new SystemLocalDateTime());
final boolean remove = condition.evaluate(suite);
assertTrue(remove);
}
Expand All @@ -155,7 +156,7 @@ public void evaluate_when8SuitesKeepNewerThan_expectFalse(String allSuitesVersio

Suite suite = mockSuiteVersionAndCreatedDate(evaluatedSuite, createdDaysAgo);
SuiteRemoveCondition condition = new SuiteRemoveCondition(suites,
mockRemoveConditions(removeOlderThan, keepNVersions));
mockRemoveConditions(removeOlderThan, keepNVersions), new SystemLocalDateTime());
final boolean remove = condition.evaluate(suite);
assertFalse(remove);
}
Expand All @@ -174,7 +175,7 @@ public void evaluate_when8SuitesKeepNewerThanAndAtLeastXVersions_expectTrue(

Suite suite = mockSuiteVersionAndCreatedDate(evaluatedSuite, createdDaysAgo);
SuiteRemoveCondition condition = new SuiteRemoveCondition(suites,
mockRemoveConditions(removeOlderThan, keepNVersions));
mockRemoveConditions(removeOlderThan, keepNVersions), new SystemLocalDateTime());
final boolean remove = condition.evaluate(suite);
assertTrue(remove);
}
Expand All @@ -193,7 +194,7 @@ public void evaluate_when8SuitesKeepNewerThanAndAtLeastXVersions_expectFalse(

Suite suite = mockSuiteVersionAndCreatedDate(evaluatedSuite, createdDaysAgo);
SuiteRemoveCondition condition = new SuiteRemoveCondition(suites,
mockRemoveConditions(removeOlderThan, keepNVersions));
mockRemoveConditions(removeOlderThan, keepNVersions), new SystemLocalDateTime());
final boolean remove = condition.evaluate(suite);
assertFalse(remove);
}
Expand All @@ -208,7 +209,7 @@ public void evaluate_whenDuplicatedVersion_expectRemoveOnlyOldVersions(String al

Suite suite = mockSuiteVersionAndCreatedDate(evaluatedSuite, createdDaysAgo);
SuiteRemoveCondition condition = new SuiteRemoveCondition(suites,
mockRemoveConditions(removeOlderThan, keepNVersions));
mockRemoveConditions(removeOlderThan, keepNVersions), new SystemLocalDateTime());
final boolean remove = condition.evaluate(suite);
assertTrue(remove);
}
Expand All @@ -224,7 +225,7 @@ public void evaluate_whenDuplicatedVersion_expectKeepNewestVersion(String allSui

Suite suite = mockSuiteVersionAndCreatedDate(evaluatedSuite, createdDaysAgo);
SuiteRemoveCondition condition = new SuiteRemoveCondition(suites,
mockRemoveConditions(removeOlderThan, keepNVersions));
mockRemoveConditions(removeOlderThan, keepNVersions), new SystemLocalDateTime());
final boolean remove = condition.evaluate(suite);
assertFalse(remove);
}
Expand Down
7 changes: 7 additions & 0 deletions integration-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,10 @@ or in `.../config/common/webdriver.properties` file.
To start the Bobcat tests, run `mvn clean test` from the `sanity-functional` directory level

[Chromedriver]: https://sites.google.com/a/chromium.org/chromedriver/

### cleaner-test

Cleaner Integration Tests are using [mocked OSGi context](https://sling.apache.org/documentation/development/osgi-mock.html)
and an [in-memory mock of MongoDB server](https://github.com/bwaldvogel/mongo-java-server).
Tests check various combinations of Cleaner parameters (versions to keep and suite max age)
and verify whether correct metadata and artifacts documents have been removed from database.
Loading