Skip to content

Commit 255ee26

Browse files
author
Vignesh Raja
authored
Release version 1.0.0 (#22)
1 parent ead2300 commit 255ee26

24 files changed

+615
-44
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 1.0.0
2+
3+
- Introduce support for Full Stack projects in Optimizely X with no breaking changes from previous version
4+
- Update whitelisting to take precedence over audience condition evaluation
5+
- Introduce more graceful exception handling in instantiation and core methods
6+
17
## 0.1.71
28

39
- Add support for v2 backend endpoint and datafile

CONTRIBUTING.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
# Contributing to the Optimizely Java SDK
22

3-
We welcome contributions and feedback! Please read the [README](README.md) to set up your development environment,
4-
then read the guidelines below for information on submitting your code.
3+
We welcome contributions and feedback! All contributors must sign our [Contributor License Agreement (CLA)](https://docs.google.com/a/optimizely.com/forms/d/e/1FAIpQLSf9cbouWptIpMgukAKZZOIAhafvjFCV8hS00XJLWQnWDFtwtA/viewform) to be eligible to contribute. Please read the [README](README.md) to set up your development environment, then read the guidelines below for information on submitting your code.
54

65
## Development process
76

8-
1. Create a branch off of `master`: `git checkout -b YOUR_NAME/branch_name`.
7+
1. Create a branch off of `devel`: `git checkout -b YOUR_NAME/branch_name`.
98
2. Commit your changes. Make sure to add tests!
109
3. Run `./gradlew clean check` to make sure there are no possible bugs.
1110
4. `git push` your changes to GitHub.
12-
5. Make sure that all unit tests are passing and that there are no merge conflicts between your branch and `master`.
13-
6. Open a pull request from `YOUR_NAME/branch_name` to `master`.
11+
5. Make sure that all unit tests are passing and that there are no merge conflicts between your branch and `devel`.
12+
6. Open a pull request from `YOUR_NAME/branch_name` to `devel`.
1413
7. A repository maintainer will review your pull request and, if all goes well, merge it!
1514

1615
## Pull request acceptance criteria

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Optimizely Java SDK
33
[![Build Status](https://travis-ci.org/optimizely/java-sdk.svg?branch=master)](https://travis-ci.org/optimizely/java-sdk)
44
[![Apache 2.0](https://img.shields.io/github/license/nebula-plugins/gradle-extra-configurations-plugin.svg)](http://www.apache.org/licenses/LICENSE-2.0)
55

6-
This repository houses the Java SDK for Optimizely's server-side testing product, which is currently in private beta.
6+
This repository houses the Java SDK for Optimizely's Full Stack product.
77

88
## Getting Started
99

@@ -18,14 +18,19 @@ following in your `build.gradle` and substitute `VERSION` for the latest SDK ver
1818
```
1919
repositories {
2020
maven {
21+
mavenCentral()
2122
url "http://optimizely.bintray.com/optimizely"
2223
}
2324
}
2425
2526
dependencies {
2627
compile 'com.optimizely.ab:core-api:{VERSION}'
27-
// optional event dispatcher implementation
2828
compile 'com.optimizely.ab:core-httpclient-impl:{VERSION}'
29+
// The SDK integrates with multiple JSON parsers, here we use
30+
// Jackson.
31+
compile 'com.fasterxml.jackson.core:jackson-core:2.7.1'
32+
compile 'com.fasterxml.jackson.core:jackson-annotations:2.7.1'
33+
compile 'com.fasterxml.jackson.core:jackson-databind:2.7.1'
2934
}
3035
```
3136

@@ -40,9 +45,8 @@ The supplied `pom` files on Bintray define module dependencies.
4045

4146
### Using the SDK
4247

43-
See the Optimizely server-side testing [developer documentation](http://developers.optimizely.com/server/reference/index.html) to learn how to set
44-
up your first custom project and use the SDK. **Please note that you must be a member of the private server-side testing beta to create custom
45-
projects and use this SDK.**
48+
See the Optimizely Full Stack [developer documentation](http://developers.optimizely.com/server/reference/index.html) to learn how to set
49+
up your first Java project and use the SDK.
4650

4751
## Development
4852

core-api/src/jmh/java/com/optimizely/ab/OptimizelyBenchmark.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.optimizely.ab;
1818

1919
import com.optimizely.ab.config.Variation;
20+
import com.optimizely.ab.config.parser.ConfigParseException;
2021
import com.optimizely.ab.event.NoopEventHandler;
2122

2223
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
@@ -65,7 +66,7 @@ public class OptimizelyBenchmark {
6566

6667
@Setup
6768
@SuppressFBWarnings(value="OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE", justification="stream is safely closed")
68-
public void setup() throws IOException {
69+
public void setup() throws IOException, ConfigParseException {
6970
Properties properties = new Properties();
7071
InputStream propertiesStream = getClass().getResourceAsStream("/benchmark.properties");
7172
properties.load(propertiesStream);

core-api/src/jmh/java/com/optimizely/ab/OptimizelyBuilderBenchmark.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package com.optimizely.ab;
1818

19+
import com.optimizely.ab.config.parser.ConfigParseException;
1920
import com.optimizely.ab.event.EventHandler;
2021
import com.optimizely.ab.event.NoopEventHandler;
2122

@@ -68,7 +69,7 @@ public void setup() throws IOException {
6869
}
6970

7071
@Benchmark
71-
public Optimizely measureOptimizelyCreation() throws IOException {
72+
public Optimizely measureOptimizelyCreation() throws IOException, ConfigParseException {
7273
return Optimizely.builder(datafile, eventHandler).build();
7374
}
7475
}

core-api/src/main/java/com/optimizely/ab/Optimizely.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.optimizely.ab.config.Experiment;
2525
import com.optimizely.ab.config.ProjectConfig;
2626
import com.optimizely.ab.config.Variation;
27+
import com.optimizely.ab.config.parser.ConfigParseException;
2728
import com.optimizely.ab.config.parser.DefaultConfigParser;
2829
import com.optimizely.ab.error.ErrorHandler;
2930
import com.optimizely.ab.error.NoOpErrorHandler;
@@ -169,7 +170,11 @@ private Optimizely(@Nonnull ProjectConfig projectConfig,
169170
logger.info("Activating user \"{}\" in experiment \"{}\".", userId, experiment.getKey());
170171
logger.debug("Dispatching impression event to URL {} with params {} and payload \"{}\".",
171172
impressionEvent.getEndpointUrl(), impressionEvent.getRequestParams(), impressionEvent.getBody());
172-
eventHandler.dispatchEvent(impressionEvent);
173+
try {
174+
eventHandler.dispatchEvent(impressionEvent);
175+
} catch (Exception e) {
176+
logger.error("Unexpected exception in event dispatcher", e);
177+
}
173178

174179
return variation;
175180
}
@@ -239,14 +244,19 @@ private void track(@Nonnull String eventName,
239244
logger.info("Tracking event \"{}\" for user \"{}\".", eventName, userId);
240245
logger.debug("Dispatching conversion event to URL {} with params {} and payload \"{}\".",
241246
conversionEvent.getEndpointUrl(), conversionEvent.getRequestParams(), conversionEvent.getBody());
242-
eventHandler.dispatchEvent(conversionEvent);
247+
try {
248+
eventHandler.dispatchEvent(conversionEvent);
249+
} catch (Exception e) {
250+
logger.error("Unexpected exception in event dispatcher", e);
251+
}
243252
}
244253

245254
//======== getVariation calls ========//
246255

247256
public @Nullable Variation getVariation(@Nonnull Experiment experiment,
248257
@Nonnull String userId) throws UnknownExperimentException {
249-
return bucketer.bucket(experiment, userId);
258+
259+
return getVariation(getProjectConfig(), experiment, Collections.<String, String>emptyMap(), userId);
250260
}
251261

252262
public @Nullable Variation getVariation(@Nonnull String experimentKey,
@@ -296,8 +306,7 @@ private void track(@Nonnull String eventName,
296306
/**
297307
* @return a {@link ProjectConfig} instance given a json string
298308
*/
299-
private static ProjectConfig getProjectConfig(String datafile) {
300-
//TODO(vignesh): add validation logic here
309+
private static ProjectConfig getProjectConfig(String datafile) throws ConfigParseException {
301310
return DefaultConfigParser.getInstance().parseProjectConfig(datafile);
302311
}
303312

@@ -466,7 +475,7 @@ protected Builder withConfig(ProjectConfig projectConfig) {
466475
return this;
467476
}
468477

469-
public Optimizely build() {
478+
public Optimizely build() throws ConfigParseException {
470479
if (projectConfig == null) {
471480
projectConfig = Optimizely.getProjectConfig(datafile);
472481
}

core-api/src/main/java/com/optimizely/ab/config/parser/ConfigParseException.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,10 @@
1616
*/
1717
package com.optimizely.ab.config.parser;
1818

19-
import com.optimizely.ab.OptimizelyRuntimeException;
20-
2119
/**
2220
* Wrapper around all types of JSON parser exceptions.
2321
*/
24-
public final class ConfigParseException extends OptimizelyRuntimeException {
25-
22+
public final class ConfigParseException extends Exception {
2623
public ConfigParseException(String message) {
2724
super(message);
2825
}

core-api/src/main/java/com/optimizely/ab/config/parser/GsonConfigParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public ProjectConfig parseProjectConfig(@Nonnull String json) throws ConfigParse
4444
try {
4545
return gson.fromJson(json, ProjectConfig.class);
4646
} catch (JsonParseException e) {
47-
throw new ConfigParseException("unable to parse project config: " + json, e);
47+
throw new ConfigParseException("Unable to parse datafile: " + json, e);
4848
}
4949
}
5050
}

core-api/src/main/java/com/optimizely/ab/config/parser/JacksonConfigParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public ProjectConfig parseProjectConfig(@Nonnull String json) throws ConfigParse
4040
try {
4141
return mapper.readValue(json, ProjectConfig.class);
4242
} catch (IOException e) {
43-
throw new ConfigParseException("unable to parse project config: " + json, e);
43+
throw new ConfigParseException("Unable to parse datafile: " + json, e);
4444
}
4545
}
4646
}

core-api/src/main/java/com/optimizely/ab/config/parser/JsonConfigParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public ProjectConfig parseProjectConfig(@Nonnull String json) throws ConfigParse
7474
return new ProjectConfig(accountId, projectId, version, revision, groups, experiments, attributes, events,
7575
audiences);
7676
} catch (JSONException e) {
77-
throw new ConfigParseException("unable to parse project config: " + json, e);
77+
throw new ConfigParseException("Unable to parse datafile: " + json, e);
7878
}
7979
}
8080

0 commit comments

Comments
 (0)