This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 40bc1ed3d80 Add test cases for ReservationPersistService (#32839)
40bc1ed3d80 is described below
commit 40bc1ed3d80f4dfe4bbc2f9b69bafec6519f207b
Author: Liang Zhang <[email protected]>
AuthorDate: Fri Sep 13 00:15:11 2024 +0800
Add test cases for ReservationPersistService (#32839)
---
.../persist/ReservationPersistServiceTest.java | 50 ++++++++++++++++++++++
1 file changed, 50 insertions(+)
diff --git
a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/ReservationPersistServiceTest.java
b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/ReservationPersistServiceTest.java
new file mode 100644
index 00000000000..e7433d5b0e1
--- /dev/null
+++
b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/ReservationPersistServiceTest.java
@@ -0,0 +1,50 @@
+/*
+ * 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.shardingsphere.mode.manager.cluster.persist;
+
+import
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
+import org.junit.jupiter.api.Test;
+
+import java.util.Optional;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+class ReservationPersistServiceTest {
+
+ private final ClusterPersistRepository repository =
mock(ClusterPersistRepository.class);
+
+ @Test
+ void assertReserveExistedWorkerId() {
+ ReservationPersistService reservationPersistService = new
ReservationPersistService(repository);
+ when(repository.persistExclusiveEphemeral("/reservation/worker_id/1",
"foo_id")).thenReturn(true);
+ Optional<Integer> actual =
reservationPersistService.reserveWorkerId(1, "foo_id");
+ assertTrue(actual.isPresent());
+ assertThat(actual.get(), is(1));
+ }
+
+ @Test
+ void assertReserveNotExistedWorkerId() {
+ ReservationPersistService reservationPersistService = new
ReservationPersistService(repository);
+ assertFalse(reservationPersistService.reserveWorkerId(1,
"foo_id").isPresent());
+ }
+}