You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by ra...@apache.org on 2017/07/18 13:16:27 UTC
[05/23] curator git commit: new generalization complete with initial
test
new generalization complete with initial test
Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/c3adc953
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/c3adc953
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/c3adc953
Branch: refs/heads/master
Commit: c3adc95315413ee5c0be861b528e80a380444e5b
Parents: 1a15582
Author: randgalt <ra...@apache.org>
Authored: Fri Jul 14 09:36:51 2017 -0500
Committer: randgalt <ra...@apache.org>
Committed: Fri Jul 14 09:36:51 2017 -0500
----------------------------------------------------------------------
.../async/modeled/migrations/MigrationManager.java | 10 +++++-----
.../modeled/migrations/TestMigrationManager.java | 17 +++++++----------
2 files changed, 12 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/curator/blob/c3adc953/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/migrations/MigrationManager.java
----------------------------------------------------------------------
diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/migrations/MigrationManager.java b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/migrations/MigrationManager.java
index 47adb1e..e59b7bf 100644
--- a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/migrations/MigrationManager.java
+++ b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/migrations/MigrationManager.java
@@ -147,13 +147,13 @@ public class MigrationManager
private CompletionStage<Void> applyMetaDataAfterEnsure(List<Migration> toBeApplied, ModeledFramework<MetaData> metaDataClient)
{
- List<CuratorOp> operations = new ArrayList<>();
- for ( Migration migration : toBeApplied )
- {
+ List<CompletableFuture<Object>> stages = toBeApplied.stream().map(migration -> {
+ List<CuratorOp> operations = new ArrayList<>();
operations.addAll(migration.operations());
MetaData thisMetaData = new MetaData(migration.id(), migration.version());
operations.add(metaDataClient.child(META_DATA_NODE_NAME).createOp(thisMetaData));
- }
- return client.transaction().forOperations(operations).thenApply(__ -> null);
+ return client.transaction().forOperations(operations).thenApply(__ -> null).toCompletableFuture();
+ }).collect(Collectors.toList());
+ return CompletableFuture.allOf(stages.toArray(new CompletableFuture[stages.size()]));
}
}
http://git-wip-us.apache.org/repos/asf/curator/blob/c3adc953/curator-x-async/src/test/java/org/apache/curator/x/async/modeled/migrations/TestMigrationManager.java
----------------------------------------------------------------------
diff --git a/curator-x-async/src/test/java/org/apache/curator/x/async/modeled/migrations/TestMigrationManager.java b/curator-x-async/src/test/java/org/apache/curator/x/async/modeled/migrations/TestMigrationManager.java
index daf69cd..9fcd53c 100644
--- a/curator-x-async/src/test/java/org/apache/curator/x/async/modeled/migrations/TestMigrationManager.java
+++ b/curator-x-async/src/test/java/org/apache/curator/x/async/modeled/migrations/TestMigrationManager.java
@@ -99,11 +99,12 @@ public class TestMigrationManager extends CompletableBaseClassForTests
v2Spec = ModelSpec.builder(modelPath, JacksonModelSerializer.build(ModelV2.class)).build();
v3Spec = ModelSpec.builder(modelPath, JacksonModelSerializer.build(ModelV3.class)).build();
- CuratorOp v1op = ModeledFramework.wrap(client, v1Spec).createOp(new ModelV1("Test"));
+ CuratorOp v1opA = client.unwrap().transactionOp().create().forPath(v1Spec.path().parent().fullPath());
+ CuratorOp v1opB = ModeledFramework.wrap(client, v1Spec).createOp(new ModelV1("Test"));
CuratorOp v2op = ModeledFramework.wrap(client, v2Spec).updateOp(new ModelV2("Test 2", 10));
CuratorOp v3op = ModeledFramework.wrap(client, v3Spec).updateOp(new ModelV3("One", "Two", 30));
- Migration m1 = Migration.build("1",1, () -> Collections.singletonList(v1op));
+ Migration m1 = Migration.build("1",1, () -> Arrays.asList(v1opA, v1opB));
Migration m2 = Migration.build("2",1, () -> Collections.singletonList(v2op));
Migration m3 = Migration.build("3",1, () -> Collections.singletonList(v3op));
migrationSet = MigrationSet.build("1", ZPath.parse("/metadata"), Arrays.asList(m1, m2, m3));
@@ -123,18 +124,14 @@ public class TestMigrationManager extends CompletableBaseClassForTests
@Test
public void testBasic() throws Exception
{
- ModeledFramework<ModelV1> v1Client = ModeledFramework.wrap(client, v1Spec);
- ModelV1 v1 = new ModelV1("John Galt");
- complete(v1Client.child("1").set(v1));
-
MigrationManager manager = new MigrationManager(client, ZPath.parse("/locks"), JacksonModelSerializer.build(MetaData.class), executor, Duration.ofMinutes(10));
complete(manager.migrate(migrationSet));
ModeledFramework<ModelV3> v3Client = ModeledFramework.wrap(client, v3Spec);
- complete(v3Client.child("1").read(), (m, e) -> {
- Assert.assertEquals(m.getAge(), 64);
- Assert.assertEquals(m.getFirstName(), "John");
- Assert.assertEquals(m.getLastName(), "Galt");
+ complete(v3Client.read(), (m, e) -> {
+ Assert.assertEquals(m.getAge(), 30);
+ Assert.assertEquals(m.getFirstName(), "One");
+ Assert.assertEquals(m.getLastName(), "Two");
});
}
}