diff --git a/core/src/main/java/com/yahoo/ycsb/DBWrapper.java b/core/src/main/java/com/yahoo/ycsb/DBWrapper.java index 0109c519558056ab0d762b64b2350dda6fa16b7c..f68ca76f5aa0c0d096098619853268398040906c 100644 --- a/core/src/main/java/com/yahoo/ycsb/DBWrapper.java +++ b/core/src/main/java/com/yahoo/ycsb/DBWrapper.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010 Yahoo! Inc. All rights reserved. + * Copyright (c) 2010 Yahoo! Inc., 2016 YCSB contributors. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); you * may not use this file except in compliance with the License. You @@ -184,7 +184,7 @@ public class DBWrapper extends DB private void measure(String op, Status result, long intendedStartTimeNanos, long startTimeNanos, long endTimeNanos) { String measurementName = op; - if (result != Status.OK) { + if (result == null || !result.isOk()) { if (this.reportLatencyForEachError || this.latencyTrackedErrors.contains(result.getName())) { measurementName = op + "-" + result.getName(); diff --git a/core/src/main/java/com/yahoo/ycsb/Status.java b/core/src/main/java/com/yahoo/ycsb/Status.java index 5e5b3a887d3f3bb6c871c950977ab2585c3fc28f..5dbf88ac8070a49a9817685595aefb680d05eb35 100644 --- a/core/src/main/java/com/yahoo/ycsb/Status.java +++ b/core/src/main/java/com/yahoo/ycsb/Status.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015 YCSB contributors All rights reserved. + * Copyright (c) 2016 YCSB contributors All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); you * may not use this file except in compliance with the License. You @@ -79,6 +79,14 @@ public class Status { return true; } + /** + * Is {@code this} a passing state for the operation: {@link Status#OK} or {@link Status#BATCHED_OK}. + * @return true if the operation is successful, false otherwise + */ + public boolean isOk() { + return this == OK || this == BATCHED_OK; + } + public static final Status OK = new Status("OK", "The operation completed successfully."); public static final Status ERROR = new Status("ERROR", "The operation failed."); public static final Status NOT_FOUND = new Status("NOT_FOUND", "The requested record was not found."); diff --git a/core/src/main/java/com/yahoo/ycsb/workloads/CoreWorkload.java b/core/src/main/java/com/yahoo/ycsb/workloads/CoreWorkload.java index b9ff7e734cf3b3224511de51e4f1b16253f00ff7..422dc05475d1534a717ab63077c7a6525ce52c5d 100644 --- a/core/src/main/java/com/yahoo/ycsb/workloads/CoreWorkload.java +++ b/core/src/main/java/com/yahoo/ycsb/workloads/CoreWorkload.java @@ -41,6 +41,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Vector; @@ -590,7 +591,7 @@ public class CoreWorkload extends Workload { int numOfRetries = 0; do { status = db.insert(table, dbkey, values); - if (status == Status.OK) { + if (null != status && status.isOk()) { break; } // Retry if configured. Without retrying, the load process will fail @@ -614,7 +615,7 @@ public class CoreWorkload extends Workload { } } while (true); - return (status == Status.OK); + return null != status && status.isOk(); } /** diff --git a/core/src/test/java/com/yahoo/ycsb/TestStatus.java b/core/src/test/java/com/yahoo/ycsb/TestStatus.java new file mode 100644 index 0000000000000000000000000000000000000000..efcc7239c86a3afdc87d5ab279c1894e06b46311 --- /dev/null +++ b/core/src/test/java/com/yahoo/ycsb/TestStatus.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) 2016 YCSB contributors. All rights reserved. + * + * Licensed 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. See accompanying + * LICENSE file. + */ +package com.yahoo.ycsb; + +import org.testng.annotations.Test; + +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; + +/** + * Test class for {@link Status}. + */ +public class TestStatus { + + @Test + public void testAcceptableStatus() { + assertTrue(Status.OK.isOk()); + assertTrue(Status.BATCHED_OK.isOk()); + assertFalse(Status.BAD_REQUEST.isOk()); + assertFalse(Status.ERROR.isOk()); + assertFalse(Status.FORBIDDEN.isOk()); + assertFalse(Status.NOT_FOUND.isOk()); + assertFalse(Status.NOT_IMPLEMENTED.isOk()); + assertFalse(Status.SERVICE_UNAVAILABLE.isOk()); + assertFalse(Status.UNEXPECTED_STATE.isOk()); + } +}