From c44e798b73d885967a4d93da1dc8b46c273adfb7 Mon Sep 17 00:00:00 2001 From: tison Date: Wed, 14 Feb 2024 11:03:05 +0800 Subject: [PATCH] monkey patch Signed-off-by: tison --- .../framework/imps/TestTransactionsNew.java | 12 ++++---- .../framework/imps/TestTransactionsOld.java | 8 ++--- .../framework/imps/TransactionsHelper.java | 30 +++++++++++++++++++ curator-test-zk37/pom.xml | 2 +- curator-test-zk38/pom.xml | 1 - 5 files changed, 41 insertions(+), 12 deletions(-) create mode 100644 curator-framework/src/test/java/org/apache/curator/framework/imps/TransactionsHelper.java diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestTransactionsNew.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestTransactionsNew.java index d8c1b30dd..8595dd06b 100644 --- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestTransactionsNew.java +++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestTransactionsNew.java @@ -125,7 +125,7 @@ public void testWithNamespace() throws Exception { assertNull(client.checkExists().forPath("/foo/bar")); CuratorTransactionResult ephemeralResult = - Iterables.find(results, CuratorTransactionResult.ofTypeAndPath(OperationType.CREATE, "/test-")); + Iterables.find(results, TransactionsHelper.ofTypeAndPath(OperationType.CREATE, "/test-")); assertNotNull(ephemeralResult); assertNotEquals(ephemeralResult.getResultPath(), "/test-"); assertTrue(ephemeralResult.getResultPath().startsWith("/test-")); @@ -148,9 +148,9 @@ public void testBasic() throws Exception { assertArrayEquals(client.getData().forPath("/foo/bar"), "snafu".getBytes()); CuratorTransactionResult fooResult = - Iterables.find(results, CuratorTransactionResult.ofTypeAndPath(OperationType.CREATE, "/foo")); + Iterables.find(results, TransactionsHelper.ofTypeAndPath(OperationType.CREATE, "/foo")); CuratorTransactionResult fooBarResult = - Iterables.find(results, CuratorTransactionResult.ofTypeAndPath(OperationType.CREATE, "/foo/bar")); + Iterables.find(results, TransactionsHelper.ofTypeAndPath(OperationType.CREATE, "/foo/bar")); assertNotNull(fooResult); assertNotNull(fooBarResult); assertNotSame(fooResult, fooBarResult); @@ -179,9 +179,9 @@ public void testBackground() throws Exception { assertArrayEquals(client.getData().forPath("/foo/bar"), "snafu".getBytes()); CuratorTransactionResult fooResult = - Iterables.find(results, CuratorTransactionResult.ofTypeAndPath(OperationType.CREATE, "/foo")); + Iterables.find(results, TransactionsHelper.ofTypeAndPath(OperationType.CREATE, "/foo")); CuratorTransactionResult fooBarResult = - Iterables.find(results, CuratorTransactionResult.ofTypeAndPath(OperationType.CREATE, "/foo/bar")); + Iterables.find(results, TransactionsHelper.ofTypeAndPath(OperationType.CREATE, "/foo/bar")); assertNotNull(fooResult); assertNotNull(fooBarResult); assertNotSame(fooResult, fooBarResult); @@ -225,7 +225,7 @@ public void testBackgroundWithNamespace() throws Exception { assertNull(client.checkExists().forPath("/foo/bar")); CuratorTransactionResult ephemeralResult = - Iterables.find(results, CuratorTransactionResult.ofTypeAndPath(OperationType.CREATE, "/test-")); + Iterables.find(results, TransactionsHelper.ofTypeAndPath(OperationType.CREATE, "/test-")); assertNotNull(ephemeralResult); assertNotEquals(ephemeralResult.getResultPath(), "/test-"); assertTrue(ephemeralResult.getResultPath().startsWith("/test-")); diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestTransactionsOld.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestTransactionsOld.java index bd00720ba..961dcf8c0 100644 --- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestTransactionsOld.java +++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestTransactionsOld.java @@ -108,7 +108,7 @@ public void testWithNamespace() throws Exception { assertNull(client.checkExists().forPath("/foo/bar")); CuratorTransactionResult ephemeralResult = - Iterables.find(results, CuratorTransactionResult.ofTypeAndPath(OperationType.CREATE, "/test-")); + Iterables.find(results, TransactionsHelper.ofTypeAndPath(OperationType.CREATE, "/test-")); assertNotNull(ephemeralResult); assertNotEquals(ephemeralResult.getResultPath(), "/test-"); assertTrue(ephemeralResult.getResultPath().startsWith("/test-")); @@ -162,7 +162,7 @@ public void testWithCompression() throws Exception { assertEquals(client.getACL().forPath("/bar"), ZooDefs.Ids.READ_ACL_UNSAFE); CuratorTransactionResult ephemeralResult = - Iterables.find(results, CuratorTransactionResult.ofTypeAndPath(OperationType.CREATE, "/test-")); + Iterables.find(results, TransactionsHelper.ofTypeAndPath(OperationType.CREATE, "/test-")); assertNotNull(ephemeralResult); assertNotEquals(ephemeralResult.getResultPath(), "/test-"); assertTrue(ephemeralResult.getResultPath().startsWith("/test-")); @@ -193,9 +193,9 @@ public void testBasic() throws Exception { assertArrayEquals(client.getData().forPath("/foo/bar"), "snafu".getBytes()); CuratorTransactionResult fooResult = - Iterables.find(results, CuratorTransactionResult.ofTypeAndPath(OperationType.CREATE, "/foo")); + Iterables.find(results, TransactionsHelper.ofTypeAndPath(OperationType.CREATE, "/foo")); CuratorTransactionResult fooBarResult = - Iterables.find(results, CuratorTransactionResult.ofTypeAndPath(OperationType.CREATE, "/foo/bar")); + Iterables.find(results, TransactionsHelper.ofTypeAndPath(OperationType.CREATE, "/foo/bar")); assertNotNull(fooResult); assertNotNull(fooBarResult); assertNotSame(fooResult, fooBarResult); diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TransactionsHelper.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TransactionsHelper.java new file mode 100644 index 000000000..8b385e32a --- /dev/null +++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TransactionsHelper.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.curator.framework.imps; + +import com.google.common.base.Predicate; +import org.apache.curator.framework.api.transaction.CuratorTransactionResult; +import org.apache.curator.framework.api.transaction.OperationType; + +public class TransactionsHelper { + public static Predicate ofTypeAndPath(OperationType type, String forPath) { + return result -> (result.getType() == type) && result.getForPath().equals(forPath); + } +} diff --git a/curator-test-zk37/pom.xml b/curator-test-zk37/pom.xml index bd9cbce32..f019bf2b8 100644 --- a/curator-test-zk37/pom.xml +++ b/curator-test-zk37/pom.xml @@ -224,7 +224,7 @@ org.apache.curator:curator-recipes org.apache.curator:curator-client - zk35TestCompatibility,zk36,zk38OrLater + zk38OrLater diff --git a/curator-test-zk38/pom.xml b/curator-test-zk38/pom.xml index 93d503467..21f8b20cb 100644 --- a/curator-test-zk38/pom.xml +++ b/curator-test-zk38/pom.xml @@ -229,7 +229,6 @@ org.apache.curator:curator-recipes org.apache.curator:curator-client - zk36,zk35TestCompatibility