aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zma...@apache.org
Subject aurora git commit: Reject NULL for enum values in H2.
Date Wed, 10 Feb 2016 21:22:51 GMT
Repository: aurora
Updated Branches:
  refs/heads/master 86b6d7919 -> d657f952a


Reject NULL for enum values in H2.

While I was working on something else, I introduced an error where MyBatis was
populating a thrift enum value and was reading in NULL. I realized that the code
would currently treat this as enum value 0 and mask the error. This patch
modifies the schema and TEnum type handler to reject populating a thrift enum
value from NULL.

Reviewed at https://reviews.apache.org/r/43397/


Project: http://git-wip-us.apache.org/repos/asf/aurora/repo
Commit: http://git-wip-us.apache.org/repos/asf/aurora/commit/d657f952
Tree: http://git-wip-us.apache.org/repos/asf/aurora/tree/d657f952
Diff: http://git-wip-us.apache.org/repos/asf/aurora/diff/d657f952

Branch: refs/heads/master
Commit: d657f952a76e8207b222879ef2490ac49c3a5901
Parents: 86b6d79
Author: Zameer Manji <zmanji@apache.org>
Authored: Wed Feb 10 13:22:44 2016 -0800
Committer: Zameer Manji <zmanji@apache.org>
Committed: Wed Feb 10 13:22:44 2016 -0800

----------------------------------------------------------------------
 .../db/typehandlers/AbstractTEnumTypeHandler.java     | 14 +++++++++++---
 .../org/apache/aurora/scheduler/storage/db/schema.sql |  2 +-
 .../apache/aurora/scheduler/cron/quartz/CronIT.java   |  2 ++
 3 files changed, 14 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aurora/blob/d657f952/src/main/java/org/apache/aurora/scheduler/storage/db/typehandlers/AbstractTEnumTypeHandler.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/storage/db/typehandlers/AbstractTEnumTypeHandler.java
b/src/main/java/org/apache/aurora/scheduler/storage/db/typehandlers/AbstractTEnumTypeHandler.java
index 892af5d..69f125b 100644
--- a/src/main/java/org/apache/aurora/scheduler/storage/db/typehandlers/AbstractTEnumTypeHandler.java
+++ b/src/main/java/org/apache/aurora/scheduler/storage/db/typehandlers/AbstractTEnumTypeHandler.java
@@ -22,6 +22,8 @@ import org.apache.ibatis.type.JdbcType;
 import org.apache.ibatis.type.TypeHandler;
 import org.apache.thrift.TEnum;
 
+import static com.google.common.base.Preconditions.checkState;
+
 /**
  * Type handler for fields of type {@link TEnum}.  Implementers need only override
  * {@link #fromValue(int)}.
@@ -47,16 +49,22 @@ abstract class AbstractTEnumTypeHandler<T extends TEnum> implements
TypeHandler<
 
   @Override
   public final T getResult(ResultSet rs, String columnName) throws SQLException {
-    return fromValue(rs.getInt(columnName));
+    int i = rs.getInt(columnName);
+    checkState(!rs.wasNull());
+    return fromValue(i);
   }
 
   @Override
   public final T getResult(ResultSet rs, int columnIndex) throws SQLException {
-    return fromValue(rs.getInt(columnIndex));
+    int i = rs.getInt(columnIndex);
+    checkState(!rs.wasNull());
+    return fromValue(i);
   }
 
   @Override
   public final T getResult(CallableStatement cs, int columnIndex) throws SQLException {
-    return fromValue(cs.getInt(columnIndex));
+    int i = cs.getInt(columnIndex);
+    checkState(!cs.wasNull());
+    return fromValue(i);
   }
 }

http://git-wip-us.apache.org/repos/asf/aurora/blob/d657f952/src/main/resources/org/apache/aurora/scheduler/storage/db/schema.sql
----------------------------------------------------------------------
diff --git a/src/main/resources/org/apache/aurora/scheduler/storage/db/schema.sql b/src/main/resources/org/apache/aurora/scheduler/storage/db/schema.sql
index 7fbdcbf..c6c1f0a 100644
--- a/src/main/resources/org/apache/aurora/scheduler/storage/db/schema.sql
+++ b/src/main/resources/org/apache/aurora/scheduler/storage/db/schema.sql
@@ -221,7 +221,7 @@ CREATE TABLE cron_jobs(
   job_key_id BIGINT NOT NULL REFERENCES job_keys(id),
   creator_user VARCHAR NOT NULL,
   cron_schedule VARCHAR NOT NULL,
-  cron_collision_policy INT REFERENCES cron_policies(id),
+  cron_collision_policy INT NOT NULL REFERENCES cron_policies(id),
   task_config_row_id BIGINT NOT NULL REFERENCES task_configs(id),
   instance_count INT NOT NULL,
 

http://git-wip-us.apache.org/repos/asf/aurora/blob/d657f952/src/test/java/org/apache/aurora/scheduler/cron/quartz/CronIT.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/cron/quartz/CronIT.java b/src/test/java/org/apache/aurora/scheduler/cron/quartz/CronIT.java
index 469b53b..1c0a3fa 100644
--- a/src/test/java/org/apache/aurora/scheduler/cron/quartz/CronIT.java
+++ b/src/test/java/org/apache/aurora/scheduler/cron/quartz/CronIT.java
@@ -47,6 +47,7 @@ import org.quartz.Scheduler;
 import org.quartz.Trigger;
 import org.quartz.TriggerListener;
 
+import static org.apache.aurora.gen.CronCollisionPolicy.KILL_EXISTING;
 import static org.easymock.EasyMock.expectLastCall;
 import static org.easymock.EasyMock.isA;
 import static org.junit.Assert.assertEquals;
@@ -65,6 +66,7 @@ public class CronIT extends EasyMockTest {
           .setKey(JOB_KEY.newBuilder())
           .setInstanceCount(2)
           .setOwner(IDENTITY)
+          .setCronCollisionPolicy(KILL_EXISTING)
           .setTaskConfig(makeTaskConfig()));
 
   private Injector injector;


Mime
View raw message