sijie closed pull request #1168: Fix TestBKSyncLogReader
URL: https://github.com/apache/bookkeeper/pull/1168
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/.travis.yml b/.travis.yml
index 156a0ba9c..d21823923 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -38,7 +38,7 @@ matrix:
       dist: trusty
       env: CUSTOM_JDK="openjdk8"
 
-before_install:
+before_install: 
 - |
     echo "MAVEN_OPTS='-Xmx3072m -XX:MaxPermSize=512m'" > ~/.mavenrc
     if [ "$TRAVIS_OS_NAME" == "osx" ]; then
@@ -54,38 +54,18 @@ before_install:
     else
         if [ `git diff --name-only $TRAVIS_COMMIT_RANGE | grep 
"^stream\/distributedlog" | wc -l` -gt 0 ]; then
             export DLOG_MODIFIED="true"  
-            echo "Enable testing distributedlog modules if this pull request 
modifies files under directory `stream/distributedlog`."
+            echo "Enable testing distributedlog modules if this pull request 
modifies files under directory 'stream/distributedlog'."
         fi
         if [ `git diff --name-only $TRAVIS_COMMIT_RANGE | grep "^site\/" | wc 
-l` -gt 0 ]; then
             # building the website to ensure the changes don't break
             export WEBSITE_MODIFIED="true"
-            echo "Enable building website modules if this pull request 
modifies files under directory `site`."
+            echo "Enable building website modules if this pull request 
modifies files under directory 'site'."
         fi
     fi
 
-script:
-- |
-    set -e
-    mvn --batch-mode clean apache-rat:check compile spotbugs:check install 
-DskipTests
-    if [ "$TRAVIS_OS_NAME" == "linux" ]; then
-        dev/check-binary-license 
./bookkeeper-dist/all/target/bookkeeper-all-*-bin.tar.gz;
-        dev/check-binary-license 
./bookkeeper-dist/server/target/bookkeeper-server-*-bin.tar.gz;
-    fi
-    if [ "$DLOG_MODIFIED" == "true" ]; then
-        cd stream/distributedlog
-        travis_wait 60 mvn --batch-mode clean package -Ddistributedlog
-        cd ../..
-    fi
-    if [ "$TRAVIS_OS_NAME" == "linux" ] && [ "$WEBSITE_MODIFIED" == "true" ]; 
then
-        cd site
-        make clean
-        # run the docker image to build the website
-        ./docker/ci.sh
-        cd ..
-    fi
+install: true
 
-# Disabled the tests here. Since tests are running much slower on Travis than 
on Jenkins
-#  - ./dev/ticktoc.sh "mvn --batch-mode clean package"
+script: .travis_scripts/build.sh
 
 cache:
   directories:
diff --git a/.travis_scripts/before_install.sh 
b/.travis_scripts/before_install.sh
new file mode 100755
index 000000000..b5b141f1c
--- /dev/null
+++ b/.travis_scripts/before_install.sh
@@ -0,0 +1,40 @@
+#!/usr/bin/env bash
+
+#
+# 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.
+#
+
+set -ev
+
+echo "MAVEN_OPTS='-Xmx3072m -XX:MaxPermSize=512m'" > ~/.mavenrc
+if [ "$TRAVIS_OS_NAME" == "osx" ]; then
+    export JAVA_HOME=$(/usr/libexec/java_home);
+fi
+echo "TRAVIS_PULL_REQUEST=${TRAVIS_PULL_REQUEST}"
+if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
+    export DLOG_MODIFIED="true"  
+    echo "Enable testing distributedlog modules since they are not pull 
requests."
+else
+    if [ `git diff --name-only $TRAVIS_COMMIT_RANGE | grep 
"^stream\/distributedlog" | wc -l` -gt 0 ]; then
+        export DLOG_MODIFIED="true"  
+        echo "Enable testing distributedlog modules if this pull request 
modifies files under directory 'stream/distributedlog'."
+    fi
+    if [ `git diff --name-only $TRAVIS_COMMIT_RANGE | grep "^site\/" | wc -l` 
-gt 0 ]; then
+        # building the website to ensure the changes don't break
+        export WEBSITE_MODIFIED="true"
+        echo "Enable building website modules if this pull request modifies 
files under directory 'site'."
+    fi
+fi
diff --git a/.travis_scripts/build.sh b/.travis_scripts/build.sh
new file mode 100755
index 000000000..d97102633
--- /dev/null
+++ b/.travis_scripts/build.sh
@@ -0,0 +1,39 @@
+#!/usr/bin/env bash
+
+#
+# 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.
+#
+
+set -ev
+
+BINDIR=`dirname "$0"`
+BK_HOME=`cd $BINDIR/..;pwd`
+
+mvn --batch-mode clean apache-rat:check compile spotbugs:check install 
-DskipTests
+if [ "$TRAVIS_OS_NAME" == "linux" ]; then
+    $BK_HOME/dev/check-binary-license 
./bookkeeper-dist/all/target/bookkeeper-all-*-bin.tar.gz;
+    $BK_HOME/dev/check-binary-license 
./bookkeeper-dist/server/target/bookkeeper-server-*-bin.tar.gz;
+fi
+if [ "$DLOG_MODIFIED" == "true" ]; then
+    cd $BK_HOME/stream/distributedlog
+    mvn --batch-mode clean package -Ddistributedlog
+fi
+if [ "$TRAVIS_OS_NAME" == "linux" ] && [ "$WEBSITE_MODIFIED" == "true" ]; then
+    cd $BK_HOME/site
+    make clean
+    # run the docker image to build the website
+    ./docker/ci.sh
+fi
diff --git a/site/README.md b/site/README.md
index 469ad27e1..3942932e3 100644
--- a/site/README.md
+++ b/site/README.md
@@ -57,3 +57,4 @@ Here are a few steps to follow to stage your changes:
 6. Your changes will be live on 
`https://<your-github-id>.github.io/bookkeeper-staging-site`.
 
 If you have any ideas to improve the review process for website, please feel 
free to contact us at d...@bookkeeper.apache.org.
+
diff --git a/stream/distributedlog/core/bin/dlog 
b/stream/distributedlog/core/bin/dlog
index 2b6af7eac..01f8ee344 100755
--- a/stream/distributedlog/core/bin/dlog
+++ b/stream/distributedlog/core/bin/dlog
@@ -70,3 +70,4 @@ case "${COMMAND}" in
     exec java $OPTS $COMMAND $@
     ;;
 esac
+
diff --git 
a/stream/distributedlog/core/src/test/java/org/apache/distributedlog/TestBKSyncLogReader.java
 
b/stream/distributedlog/core/src/test/java/org/apache/distributedlog/TestBKSyncLogReader.java
index a5d4c1632..ec99e7acf 100644
--- 
a/stream/distributedlog/core/src/test/java/org/apache/distributedlog/TestBKSyncLogReader.java
+++ 
b/stream/distributedlog/core/src/test/java/org/apache/distributedlog/TestBKSyncLogReader.java
@@ -184,26 +184,19 @@ public void testReadRecordsAfterReadAheadCaughtUp() 
throws Exception {
 
         logger.info("Write another 10 records");
 
-        // wait until readahead move on
-        while (reader.getReadAheadReader().getNextEntryPosition().getEntryId() 
< 21) {
-            TimeUnit.MILLISECONDS.sleep(20);
-        }
-
-        logger.info("ReadAhead is caught up with another 10 records");
-
-        // resume reading from sync reader. so it should be able to read all 
20 records
-        // and return null to claim it as caughtup
-        LogRecord record = reader.readNext(false);
-        int numReads = 0;
+        // resume reading from sync reader util it consumes 20 records
         long expectedTxId = 1L;
-        while (null != record) {
-            ++numReads;
+        for (int i = 0; i < 20; i++) {
+            LogRecord record = reader.readNext(false);
+            while (null == record) {
+                record = reader.readNext(false);
+            }
             assertEquals(expectedTxId, record.getTransactionId());
             DLMTestUtil.verifyLogRecord(record);
             ++expectedTxId;
-            record = reader.readNext(false);
         }
-        assertEquals(20, numReads);
+        // after read 20 records, it should return null
+        assertNull(reader.readNext(false));
 
         out.close();
         reader.close();


 

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


With regards,
Apache Git Services

Reply via email to