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

Added: AATesting #536

Merged
merged 1 commit into from
Feb 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.algolia.search.inputs.analytics;

import com.algolia.search.objects.Query;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand All @@ -23,6 +24,7 @@ public class Variant implements Serializable {
private int noResultCount;
private int searchCount;
private int userCount;
private Query customSearchParameters;

public Variant() {}

Expand Down Expand Up @@ -135,4 +137,14 @@ public int getUserCount() {
public void setUserCount(int userCount) {
this.userCount = userCount;
}

@JsonProperty
public Query getCustomSearchParameters() {
return customSearchParameters;
}

@JsonProperty
public void setCustomSearchParameters(Query customSearchParameters) {
this.customSearchParameters = customSearchParameters;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import com.algolia.search.inputs.analytics.ABTest;
import com.algolia.search.inputs.analytics.Variant;
import com.algolia.search.integration.common.ABTestingHelpersTest;
import com.algolia.search.objects.IgnorePlurals;
import com.algolia.search.objects.Query;
import com.algolia.search.objects.tasks.async.AsyncTaskABTest;
import com.algolia.search.responses.ABTests;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -64,7 +66,7 @@ public void createModifyAndDeleteABTests() throws Exception {

waitForCompletion(analytics.addABTest(abtest));

Boolean found = false;
boolean found = false;
while (!found) {
abTests = analytics.getABTests(0, 10).get();
found =
Expand All @@ -83,4 +85,35 @@ public void createModifyAndDeleteABTests() throws Exception {
abTests = analytics.getABTests(0, 10).get();
assertThat(abTests.getCount()).isEqualTo(0);
}

@Test
public void TestAATesting() throws Exception {
AsyncAnalytics analytics = createAnalytics();
AsyncIndex<AlgoliaObject> index = createIndex(AlgoliaObject.class);
waitForCompletion(index.addObject(new AlgoliaObject("algolia", 1)));

LocalDateTime now = LocalDateTime.now();

Variant variantWithSearchParam = new Variant(index.getName(), 10, null);
variantWithSearchParam.setCustomSearchParameters(
new Query().setIgnorePlurals(IgnorePlurals.of(true)));

ABTest abtest =
new ABTest(
"AA_Testing",
Arrays.asList(
new Variant(index.getName(), 90, "a description"), variantWithSearchParam),
now.plus(1, ChronoUnit.DAYS));

AsyncTaskABTest abTestTask = analytics.addABTest(abtest).get();

index.waitTask(abTestTask.getTaskID());

ABTest inserted = analytics.getABTest(abTestTask.abTestID).get();

ABTestingHelpersTest.compareABTests(abtest, inserted);
assertThat(inserted.getVariants().get(1).getCustomSearchParameters().getIgnorePlurals())
.isEqualTo(variantWithSearchParam.getCustomSearchParameters().getIgnorePlurals());
waitForCompletion(analytics.deleteABTest(abTestTask.abTestID));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.algolia.search.inputs.analytics.ABTest;
import com.algolia.search.inputs.analytics.Variant;
import com.algolia.search.integration.common.ABTestingHelpersTest;
import com.algolia.search.objects.IgnorePlurals;
import com.algolia.search.objects.Query;
import com.algolia.search.objects.tasks.sync.TaskABTest;
import com.algolia.search.responses.ABTests;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -77,10 +79,41 @@ public void createModifyAndDeleteABTests() throws AlgoliaException, InterruptedE
assertThat(inserted.getStatus()).isEqualTo("stopped");

waitForCompletion(analytics.deleteABTest(inserted.getAbTestID()));
Boolean isEmpty = false;
boolean isEmpty = false;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure you need a boolean reference here.

while (!isEmpty) {
isEmpty = analytics.getABTests(0, 10).getCount() == 0;
Thread.sleep(1000);
}
}

@Test
public void TestAATesting() throws Exception {
Analytics analytics = createAnalytics();
Index<AlgoliaObject> index = createIndex(AlgoliaObject.class);
waitForCompletion(index.addObject(new AlgoliaObject("algolia", 1)));

LocalDateTime now = LocalDateTime.now();

Variant variantWithSearchParam = new Variant(index.getName(), 10, null);
variantWithSearchParam.setCustomSearchParameters(
new Query().setIgnorePlurals(IgnorePlurals.of(true)));

ABTest abtest =
new ABTest(
"AA_Testing",
Arrays.asList(
new Variant(index.getName(), 90, "a description"), variantWithSearchParam),
now.plus(1, ChronoUnit.DAYS));

TaskABTest abTestTask = analytics.addABTest(abtest);

index.waitTask(abTestTask.getTaskID());

ABTest inserted = analytics.getABTest(abTestTask.abTestID);

ABTestingHelpersTest.compareABTests(abtest, inserted);
assertThat(inserted.getVariants().get(1).getCustomSearchParameters().getIgnorePlurals())
.isEqualTo(variantWithSearchParam.getCustomSearchParameters().getIgnorePlurals());
waitForCompletion(analytics.deleteABTest(abTestTask.abTestID));
}
}