You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2019/12/11 09:54:15 UTC

[GitHub] [hadoop-ozone] elek commented on a change in pull request #310: HDDS-2542: Race condition between read and write stateMachineData.

elek commented on a change in pull request #310: HDDS-2542: Race condition between read and write stateMachineData.
URL: https://github.com/apache/hadoop-ozone/pull/310#discussion_r356490662
 
 

 ##########
 File path: hadoop-hdds/common/src/test/java/org/apache/hadoop/hdds/utils/TestResourceLimitCache.java
 ##########
 @@ -0,0 +1,82 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hdds.utils;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Test for ResourceLimitCache.
+ */
+public class TestResourceLimitCache {
+
+  @Test
+  public void testResourceLimitCache() throws InterruptedException {
+    Cache<Integer, String> resourceCache =
+        new ResourceLimitCache<>(new ConcurrentHashMap<>(),
+            (k, v) -> new int[] {k}, 10);
+    resourceCache.put(6, "a");
+    resourceCache.put(4, "a");
+
+    // put should pass as key 4 will be overwritten
+    resourceCache.put(4, "a");
+
+    // Create a future which blocks to put 1. Currently map has acquired 10
+    // permits out of 10
+    CompletableFuture future = CompletableFuture.supplyAsync(() -> {
+      try {
+        return resourceCache.put(1, "a");
+      } catch (InterruptedException e) {
+        e.printStackTrace();
+      }
+      return null;
+    });
+    Thread.sleep(100);
 
 Review comment:
   Thank you very much @lokeshj1703 to address this issue.
   
   I didn't check the full pach, but usually the Thread.sleep(...) cause test intermittency as in the CI environment it's possible that we have slower cpu than the local cpu.
   
   Using GenericTestUtil.waitFor (with longer timeout and shorter checking period) can be more safe (IMHO).

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: ozone-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: ozone-issues-help@hadoop.apache.org