Skip to content

feat(dfm): Datafile management implementation #160

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

Merged
merged 28 commits into from
Jun 7, 2019
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5cbd740
Initial structure
msohailhussain Apr 9, 2019
f6487ae
cleanup
msohailhussain Apr 9, 2019
e385a95
added builder class
msohailhussain Apr 10, 2019
4eb4104
Extracted ProjectConfig into its own interface and updated HttpProjec…
mfahadahmed Apr 10, 2019
33cc9fa
Added polling unit tests.
mfahadahmed Apr 10, 2019
16729e9
Working on Config manager.
mfahadahmed Apr 11, 2019
43c1175
Extacted ProjectConfig into a separate interface and create DatafileP…
mfahadahmed Apr 12, 2019
904072e
Removed old ProjectConfig references.
mfahadahmed Apr 12, 2019
9586f2c
Merge remote-tracking branch 'origin/master' into sohail/dfm
mfahadahmed Apr 12, 2019
cadf4ee
Fixed missing file references.
mfahadahmed Apr 12, 2019
f49e833
Update ConfigManager classes to block execution until ProjectConfig r…
mfahadahmed Apr 23, 2019
6189f26
Added config manager unit tests and fix failing tests.
mfahadahmed Apr 24, 2019
5f9a371
Updated fm
msohailhussain May 23, 2019
e287ee7
Added unit tests and AtomicProjectConfigManager class.
mfahadahmed May 24, 2019
74a2833
Adding unit tests.
msohailhussain May 29, 2019
1d6b3d6
unit test added and 4.0 compat.
msohailhussain May 29, 2019
44d94c4
Resolved compatible issues.
msohailhussain May 29, 2019
2b220b0
Merge branch 'master' into sohail/dfm
msohailhussain May 29, 2019
dc20812
Removed DFM implementation in Optimizely from this PR. Mainly focus o…
msohailhussain May 30, 2019
a285f1e
Resolved datafile management namespace issue.
msohailhussain May 30, 2019
72869c7
Datafilemore cleanup
msohailhussain May 30, 2019
7f209a2
Moved ProjectConfig file
msohailhussain May 31, 2019
99e7a11
renamed to fallback project config manager
msohailhussain May 31, 2019
0c51253
Remover parse and added logger and error handler
msohailhussain May 31, 2019
249b201
Changed namespace & removed SetConfig from interface.
msohailhussain Jun 3, 2019
6297b83
comments addressed.
msohailhussain Jun 4, 2019
80a4014
matt’s feedback added.
msohailhussain Jun 4, 2019
aaac4e8
Nit fix
msohailhussain Jun 4, 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
15 changes: 12 additions & 3 deletions OptimizelySDK.Net35/OptimizelySDK.Net35.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,6 @@
<Compile Include="..\OptimizelySDK\Optimizely.cs">
<Link>Optimizely.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\ProjectConfig.cs">
<Link>ProjectConfig.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Utils\ConfigParser.cs">
<Link>Utils\ConfigParser.cs</Link>
</Compile>
Expand Down Expand Up @@ -218,6 +215,18 @@
<Compile Include="..\OptimizelySDK\Entity\Rollout.cs">
<Link>Entity\Rollout</Link>
</Compile>
<Compile Include="..\OptimizelySDK\ProjectConfig.cs">
<Link>ProjectConfig</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Config\DatafileProjectConfig.cs">
<Link>Config\DatafileProjectConfig</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Config\ProjectConfigManager.cs">
<Link>Config\ProjectConfigManager</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Config\FallbackProjectConfigManager.cs">
<Link>Config\FallbackProjectConfigManager.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="..\OptimizelySDK\Utils\schema.json">
Expand Down
21 changes: 18 additions & 3 deletions OptimizelySDK.Net40/OptimizelySDK.Net40.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,6 @@
<Compile Include="..\OptimizelySDK\Optimizely.cs">
<Link>Optimizely.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\ProjectConfig.cs">
<Link>ProjectConfig.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Utils\ConfigParser.cs">
<Link>Utils\ConfigParser.cs</Link>
</Compile>
Expand Down Expand Up @@ -219,6 +216,24 @@
<Compile Include="..\OptimizelySDK\Entity\Rollout.cs">
<Link>Entity\Rollout</Link>
</Compile>
<Compile Include="..\OptimizelySDK\ProjectConfig.cs">
<Link>ProjectConfig</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Config\DatafileProjectConfig.cs">
<Link>Config\DatafileProjectConfig</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Config\ProjectConfigManager.cs">
<Link>Config\ProjectConfigManager</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Config\PollingProjectConfigManager.cs">
<Link>Config\PollingProjectConfigManager</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Config\HttpProjectConfigManager.cs">
<Link>Config\HttpProjectConfigManager</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Config\FallbackProjectConfigManager.cs">
<Link>Config\FallbackProjectConfigManager.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="..\OptimizelySDK\Utils\schema.json">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
<Compile Include="..\OptimizelySDK\Logger\NoOpLogger.cs" />
<Compile Include="..\OptimizelySDK\Notifications\NotificationCenter.cs" />
<Compile Include="..\OptimizelySDK\Optimizely.cs" />
<Compile Include="..\OptimizelySDK\ProjectConfig.cs" />
<Compile Include="..\OptimizelySDK\Utils\EventTagUtils.cs" />
<Compile Include="..\OptimizelySDK\Utils\Validator.cs" />
<Compile Include=".\Properties\AssemblyInfo.cs" />
Expand All @@ -69,6 +68,14 @@
<Compile Include="..\OptimizelySDK\Bucketing\UserProfile.cs" />
<Compile Include="..\OptimizelySDK\Bucketing\UserProfileService.cs" />
<Compile Include="..\OptimizelySDK\Bucketing\UserProfileUtil.cs" />
<Compile Include="..\OptimizelySDK\ProjectConfig.cs" />
<Compile Include="..\OptimizelySDK\Config\DatafileProjectConfig.cs" />
<Compile Include="..\OptimizelySDK\Config\ProjectConfigManager.cs" />
<Compile Include="..\OptimizelySDK\Config\PollingProjectConfigManager.cs" />
<Compile Include="..\OptimizelySDK\Config\HttpProjectConfigManager.cs" />
<Compile Include="..\OptimizelySDK\Config\FallbackProjectConfigManager.cs">
<Link>AtomicProjectConfigManager.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="..\OptimizelySDK\Utils\schema.json">
Expand Down
17 changes: 17 additions & 0 deletions OptimizelySDK.NetStandard16/OptimizelySDK.NetStandard16.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OptimizelySDK.NetStandard16", "OptimizelySDK.NetStandard16.csproj", "{0A7EBA5C-A049-48AE-861D-8881EFA6B9E2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Release|Any CPU = Release|Any CPU
Debug|Any CPU = Debug|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0A7EBA5C-A049-48AE-861D-8881EFA6B9E2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0A7EBA5C-A049-48AE-861D-8881EFA6B9E2}.Release|Any CPU.Build.0 = Release|Any CPU
{0A7EBA5C-A049-48AE-861D-8881EFA6B9E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0A7EBA5C-A049-48AE-861D-8881EFA6B9E2}.Debug|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using Moq;
using NUnit.Framework;
using OptimizelySDK.AudienceConditions;
using OptimizelySDK.Config;
using OptimizelySDK.Entity;
using OptimizelySDK.Logger;

Expand Down
3 changes: 2 additions & 1 deletion OptimizelySDK.Tests/BucketerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Moq;
using NUnit.Framework;
using OptimizelySDK.Bucketing;
using OptimizelySDK.Config;
using OptimizelySDK.Entity;
using OptimizelySDK.Logger;

Expand Down Expand Up @@ -58,7 +59,7 @@ public override string ToString()
public void Initialize()
{
LoggerMock = new Mock<ILogger>();
Config = ProjectConfig.Create(TestData.Datafile, LoggerMock.Object, new ErrorHandler.NoOpErrorHandler());
Config = DatafileProjectConfig.Create(TestData.Datafile, LoggerMock.Object, new ErrorHandler.NoOpErrorHandler());
}

[TestFixtureSetUp]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2019, Optimizely
*
* 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.
*/

using NUnit.Framework;
using OptimizelySDK.Config;

namespace OptimizelySDK.Tests.DatafileManagement_Tests
{
[TestFixture]
public class AtomicProjectConfigManagerTest
{
private FallbackProjectConfigManager ConfigManager = new FallbackProjectConfigManager();

[Test]
public void TestStaticProjectConfigManagerReturnsCorrectProjectConfig()
{
var expectedConfig = DatafileProjectConfig.Create(TestData.TypedAudienceDatafile, null, null);
ConfigManager.SetConfig(expectedConfig);
Assert.True(TestData.CompareObjects(expectedConfig, ConfigManager.GetConfig()));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* Copyright 2019, Optimizely
*
* 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.
*/

using Moq;
using NUnit.Framework;
using OptimizelySDK.Config;
using OptimizelySDK.Logger;
using System;
using System.Diagnostics;

namespace OptimizelySDK.Tests.DatafileManagement_Tests
{
[TestFixture]
public class HttpProjectConfigManagerTest
{
private Mock<ILogger> LoggerMock;

[SetUp]
public void Setup()
{
LoggerMock = new Mock<ILogger>();
LoggerMock.Setup(l => l.Log(It.IsAny<LogLevel>(), It.IsAny<string>()));
}

[Test]
public void TestHttpConfigManagerRetreiveProjectConfigByURL()
{
HttpProjectConfigManager httpManager = new HttpProjectConfigManager.Builder()
.WithUrl("https://cdn.optimizely.com/datafiles/QBw9gFM8oTn7ogY9ANCC1z.json")
.WithLogger(LoggerMock.Object)
.WithPollingInterval(TimeSpan.FromMilliseconds(1000))
.WithBlockingTimeoutPeriod(TimeSpan.FromMilliseconds(500))
.Build();

httpManager.OnReady().Wait(System.Threading.Timeout.Infinite);
Assert.NotNull(httpManager.GetConfig());
}

[Test]
public void TestHttpConfigManagerRetreiveProjectConfigBySDKKey()
{
HttpProjectConfigManager httpManager = new HttpProjectConfigManager.Builder()
.WithSdkKey("QBw9gFM8oTn7ogY9ANCC1z")
.WithLogger(LoggerMock.Object)
.WithPollingInterval(TimeSpan.FromMilliseconds(1000))
.WithBlockingTimeoutPeriod(TimeSpan.FromMilliseconds(500))
.Build();

httpManager.OnReady().Wait(System.Threading.Timeout.Infinite);
Assert.NotNull(httpManager.GetConfig());
}

[Test]
public void TestHttpConfigManagerRetreiveProjectConfigByFormat()
{
HttpProjectConfigManager httpManager = new HttpProjectConfigManager.Builder()
.WithSdkKey("10192104166")
.WithFormat("https://cdn.optimizely.com/json/{0}.json")
.WithLogger(LoggerMock.Object)
.WithPollingInterval(TimeSpan.FromMilliseconds(1000))
.WithBlockingTimeoutPeriod(TimeSpan.FromMilliseconds(500))
.Build();

httpManager.OnReady().Wait(System.Threading.Timeout.Infinite);
Assert.NotNull(httpManager.GetConfig());
}

[Test]
public void TestOnReadyPromiseResolvedImmediatelyWhenDatafileIsProvided()
{
var stopwatch = new Stopwatch();
HttpProjectConfigManager httpManager = new HttpProjectConfigManager.Builder()
.WithSdkKey("10192104166")
.WithDatafile(TestData.Datafile)
.WithLogger(LoggerMock.Object)
.WithPollingInterval(TimeSpan.FromMilliseconds(1000))
.WithBlockingTimeoutPeriod(TimeSpan.FromMilliseconds(500))
.Build();

stopwatch.Start();
httpManager.OnReady().Wait();
stopwatch.Stop();

Assert.True(stopwatch.Elapsed.Seconds == 0);
Assert.NotNull(httpManager.GetConfig());
}
}
}
Loading