You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by ji...@apache.org on 2024/11/18 09:23:28 UTC
(hadoop) 12/40: Integration of TOS: Add lazy reload interface to common. test
This is an automated email from the ASF dual-hosted git repository.
jinglun pushed a commit to branch HADOOP-19236
in repository https://gitbox.apache.org/repos/asf/hadoop.git
commit 1047ad98fc79727d24888364e35be8190f57813e
Author: lijinglun <li...@bytedance.com>
AuthorDate: Thu Aug 15 19:20:42 2024 +0800
Integration of TOS: Add lazy reload interface to common. test
---
.../hadoop/fs/tosfs/util/TestLazyReload.java | 93 ++++++++++++++++++++++
1 file changed, 93 insertions(+)
diff --git a/hadoop-cloud-storage-project/hadoop-tos/src/test/java/org/apache/hadoop/fs/tosfs/util/TestLazyReload.java b/hadoop-cloud-storage-project/hadoop-tos/src/test/java/org/apache/hadoop/fs/tosfs/util/TestLazyReload.java
new file mode 100644
index 00000000000..de4ebf9ffaf
--- /dev/null
+++ b/hadoop-cloud-storage-project/hadoop-tos/src/test/java/org/apache/hadoop/fs/tosfs/util/TestLazyReload.java
@@ -0,0 +1,93 @@
+/*
+ * 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.hadoop.fs.tosfs.util;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+public class TestLazyReload {
+ @Test
+ public void testLoadWithFilterCondition() {
+ LazyReload<Integer> integers = new LazyReload<>(() -> {
+ Iterator<Integer> source = Arrays.asList(1, 3, 5, 2, 4, 6).iterator();
+ return buf -> {
+ if (!source.hasNext()) {
+ return true;
+ }
+
+ int pollCnt = 2;
+ while (source.hasNext() && pollCnt-- > 0) {
+ Integer item = source.next();
+ if (item % 2 == 0) {
+ buf.add(item);
+ }
+ }
+
+ return !source.hasNext();
+ };
+ });
+
+ Iterator<Integer> iterator = integers.iterator();
+ Assert.assertTrue(iterator.hasNext());
+ Assert.assertEquals(2, (int) iterator.next());
+ Assert.assertEquals(4, (int) iterator.next());
+ Assert.assertEquals(6, (int) iterator.next());
+ Assert.assertFalse(iterator.hasNext());
+ }
+
+ @Test
+ public void testLoadResultIsIdempotent() {
+ LazyReload<Integer> integers = new LazyReload<>(() -> {
+ Iterator<Integer> source = Arrays.asList(1, 3, 5, 2, 4, 6).iterator();
+ return buf -> {
+ if (!source.hasNext()) {
+ return true;
+ }
+
+ int pollCnt = 2;
+ while (source.hasNext() && pollCnt-- > 0) {
+ Integer item = source.next();
+ buf.add(item);
+ }
+
+ return !source.hasNext();
+ };
+ });
+ Iterator<Integer> iterator1 = integers.iterator();
+ Iterator<Integer> iterator2 = integers.iterator();
+
+ Assert.assertEquals(1, (int) iterator1.next());
+ Assert.assertEquals(1, (int) iterator2.next());
+ Assert.assertEquals(3, (int) iterator1.next());
+ Assert.assertEquals(3, (int) iterator2.next());
+ Assert.assertEquals(5, (int) iterator1.next());
+ Assert.assertEquals(5, (int) iterator2.next());
+
+ Assert.assertEquals(2, (int) iterator1.next());
+ Assert.assertEquals(4, (int) iterator1.next());
+ Assert.assertEquals(6, (int) iterator1.next());
+ Assert.assertEquals(2, (int) iterator2.next());
+ Assert.assertEquals(4, (int) iterator2.next());
+ Assert.assertEquals(6, (int) iterator2.next());
+ }
+}
+
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org