You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by li...@apache.org on 2018/02/04 00:51:34 UTC
[31/50] [abbrv] kylin git commit: KYLIN-3090,
complete UUID if entity hasn't.
KYLIN-3090, complete UUID if entity hasn't.
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/95e3d077
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/95e3d077
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/95e3d077
Branch: refs/heads/sync
Commit: 95e3d077cb69b2e8086b4646c173e0098f44f265
Parents: adf645e
Author: tttMelody <24...@qq.com>
Authored: Mon Jan 15 18:48:57 2018 +0800
Committer: Li Yang <li...@apache.org>
Committed: Fri Jan 26 22:54:58 2018 +0800
----------------------------------------------------------------------
.../metadata/cachesync/CachedCrudAssist.java | 8 ++-
.../cachesync/CachedCrudAssistTest.java | 63 ++++++++++++++++++++
2 files changed, 70 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kylin/blob/95e3d077/core-metadata/src/main/java/org/apache/kylin/metadata/cachesync/CachedCrudAssist.java
----------------------------------------------------------------------
diff --git a/core-metadata/src/main/java/org/apache/kylin/metadata/cachesync/CachedCrudAssist.java b/core-metadata/src/main/java/org/apache/kylin/metadata/cachesync/CachedCrudAssist.java
index c7244fe..b3c200e 100644
--- a/core-metadata/src/main/java/org/apache/kylin/metadata/cachesync/CachedCrudAssist.java
+++ b/core-metadata/src/main/java/org/apache/kylin/metadata/cachesync/CachedCrudAssist.java
@@ -173,7 +173,7 @@ abstract public class CachedCrudAssist<T extends RootPersistentEntity> {
public T save(T entity) throws IOException {
Preconditions.checkArgument(entity != null);
- Preconditions.checkArgument(entity.getUuid() != null);
+ completeUuidIfNeeded(entity);
Preconditions.checkArgument(entityType.isInstance(entity));
String resName = entity.resourceName();
@@ -199,6 +199,12 @@ abstract public class CachedCrudAssist<T extends RootPersistentEntity> {
return reload(resName);
}
+ private void completeUuidIfNeeded(T entity) {
+ if (entity.getUuid() == null) {
+ entity.updateRandomUuid();
+ }
+ }
+
public void delete(T entity) throws IOException {
delete(entity.resourceName());
}
http://git-wip-us.apache.org/repos/asf/kylin/blob/95e3d077/core-metadata/src/test/java/org/apache/kylin/metadata/cachesync/CachedCrudAssistTest.java
----------------------------------------------------------------------
diff --git a/core-metadata/src/test/java/org/apache/kylin/metadata/cachesync/CachedCrudAssistTest.java b/core-metadata/src/test/java/org/apache/kylin/metadata/cachesync/CachedCrudAssistTest.java
new file mode 100644
index 0000000..482ec09
--- /dev/null
+++ b/core-metadata/src/test/java/org/apache/kylin/metadata/cachesync/CachedCrudAssistTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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.kylin.metadata.cachesync;
+
+import java.io.IOException;
+
+import org.apache.kylin.common.persistence.RootPersistentEntity;
+import org.apache.kylin.common.util.LocalFileMetadataTestCase;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class CachedCrudAssistTest extends LocalFileMetadataTestCase {
+ @Before
+ public void setup() throws Exception {
+ staticCreateTestMetadata();
+ }
+
+ @Test
+ public void testSave() throws IOException {
+ CachedCrudAssist<TestEntity> crudAssist = new CachedCrudAssist<TestEntity>(getStore() //
+ , "/test" //
+ , TestEntity.class //
+ , new CaseInsensitiveStringCache<TestEntity>(getTestConfig(), "test")) { //
+ @Override
+ protected TestEntity initEntityAfterReload(TestEntity entity, String resourceName) {
+ return entity;
+ }
+ };
+
+ TestEntity entity = new TestEntity();
+ Assert.assertNull(entity.getUuid());
+ crudAssist.save(entity);
+ Assert.assertNotNull(entity.getUuid());
+ }
+
+ @After
+ public void after() throws Exception {
+ cleanAfterClass();
+ }
+}
+
+class TestEntity extends RootPersistentEntity {
+ public TestEntity() {
+ }
+}
\ No newline at end of file