phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jamestay...@apache.org
Subject [2/5] git commit: PHOENIX-1214 SYSTEM.CATALOG cannot be created when first connection to cluster is tenant-specific (Jan Van Besien)
Date Fri, 17 Oct 2014 07:50:41 GMT
PHOENIX-1214 SYSTEM.CATALOG cannot be created when first connection to cluster is tenant-specific
(Jan Van Besien)

Conflicts:
	phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
	phoenix-core/src/main/java/org/apache/phoenix/util/JDBCUtil.java
	phoenix-core/src/test/java/org/apache/phoenix/util/JDBCUtilTest.java


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

Branch: refs/heads/3.0
Commit: 9833f072285ac5983a17426821a7a4cc3a5c50fd
Parents: 660b7d9
Author: James Taylor <jtaylor@salesforce.com>
Authored: Wed Oct 15 22:18:07 2014 -0700
Committer: James Taylor <jtaylor@salesforce.com>
Committed: Thu Oct 16 20:58:17 2014 -0700

----------------------------------------------------------------------
 .../phoenix/end2end/CSVCommonsLoaderIT.java     |  4 ++-
 .../query/ConnectionQueryServicesImpl.java      |  4 ++-
 .../query/ConnectionlessQueryServicesImpl.java  |  4 ++-
 .../java/org/apache/phoenix/util/JDBCUtil.java  | 16 +++++++++
 .../apache/phoenix/jdbc/PhoenixDriverTest.java  | 31 ++++++++---------
 .../org/apache/phoenix/util/JDBCUtilTest.java   | 35 ++++++++++++++++++++
 6 files changed, 76 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/9833f072/phoenix-core/src/it/java/org/apache/phoenix/end2end/CSVCommonsLoaderIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CSVCommonsLoaderIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CSVCommonsLoaderIT.java
index 9f36b93..f51f908 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CSVCommonsLoaderIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CSVCommonsLoaderIT.java
@@ -30,10 +30,12 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.Properties;
 
 import org.apache.commons.csv.CSVParser;
 import org.apache.commons.csv.CSVRecord;
 import org.apache.phoenix.jdbc.PhoenixConnection;
+import org.apache.phoenix.jdbc.PhoenixTestDriver;
 import org.apache.phoenix.schema.PArrayDataType;
 import org.apache.phoenix.schema.PDataType;
 import org.apache.phoenix.util.CSVCommonsLoader;
@@ -156,7 +158,7 @@ public class CSVCommonsLoaderIT extends BaseHBaseManagedTimeIT {
                     new StringReader(statements), null);
             globalConn.close();
 
-            tenantConn = DriverManager.getConnection(getUrl() + ";TenantId=acme").unwrap(
+            tenantConn = new PhoenixTestDriver().connect(getUrl() + ";TenantId=acme", new
Properties()).unwrap(
                     PhoenixConnection.class);
 
             // Upsert CSV file

http://git-wip-us.apache.org/repos/asf/phoenix/blob/9833f072/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
index 03ecbc9..3a03401 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
@@ -107,6 +107,7 @@ import org.apache.phoenix.schema.TableNotFoundException;
 import org.apache.phoenix.schema.stats.PTableStats;
 import org.apache.phoenix.util.ByteUtil;
 import org.apache.phoenix.util.Closeables;
+import org.apache.phoenix.util.JDBCUtil;
 import org.apache.phoenix.util.MetaDataUtil;
 import org.apache.phoenix.util.PhoenixContextExecutor;
 import org.apache.phoenix.util.PhoenixRuntime;
@@ -1318,8 +1319,9 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices
implement
                                     PhoenixRuntime.CURRENT_SCN_ATTRIB,
                                     Long.toString(MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP));
                             scnProps.remove(PhoenixRuntime.TENANT_ID_ATTRIB);
+                            String globalUrl = JDBCUtil.removeProperty(url, PhoenixRuntime.TENANT_ID_ATTRIB);
                             metaConnection = new PhoenixConnection(
-                                    ConnectionQueryServicesImpl.this, url, scnProps, newEmptyMetaData());
+                                    ConnectionQueryServicesImpl.this, globalUrl, scnProps,
newEmptyMetaData());
                             try {
                                 metaConnection.createStatement().executeUpdate(QueryConstants.CREATE_TABLE_METADATA);
                             } catch (NewerTableAlreadyExistsException ignore) {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/9833f072/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionlessQueryServicesImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionlessQueryServicesImpl.java
b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionlessQueryServicesImpl.java
index dd0cf54..3cd7917 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionlessQueryServicesImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionlessQueryServicesImpl.java
@@ -66,6 +66,7 @@ import org.apache.phoenix.schema.SequenceNotFoundException;
 import org.apache.phoenix.schema.TableAlreadyExistsException;
 import org.apache.phoenix.schema.TableNotFoundException;
 import org.apache.phoenix.schema.stats.PTableStats;
+import org.apache.phoenix.util.JDBCUtil;
 import org.apache.phoenix.util.MetaDataUtil;
 import org.apache.phoenix.util.PhoenixRuntime;
 import org.apache.phoenix.util.PropertiesUtil;
@@ -208,7 +209,8 @@ public class ConnectionlessQueryServicesImpl extends DelegateQueryServices
imple
                 Properties scnProps = PropertiesUtil.deepCopy(props);
                 scnProps.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP));
                 scnProps.remove(PhoenixRuntime.TENANT_ID_ATTRIB);
-                metaConnection = new PhoenixConnection(this, url, scnProps, newEmptyMetaData());
+                String globalUrl = JDBCUtil.removeProperty(url, PhoenixRuntime.TENANT_ID_ATTRIB);
+                metaConnection = new PhoenixConnection(this, globalUrl, scnProps, newEmptyMetaData());
                 try {
                     metaConnection.createStatement().executeUpdate(QueryConstants.CREATE_TABLE_METADATA);
                 } catch (TableAlreadyExistsException ignore) {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/9833f072/phoenix-core/src/main/java/org/apache/phoenix/util/JDBCUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/JDBCUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/JDBCUtil.java
index 6148417..ff7ec20 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/JDBCUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/JDBCUtil.java
@@ -64,6 +64,22 @@ public class JDBCUtil {
         return propValue;
     }
 
+    public static String removeProperty(String url, String propName) {
+        String urlPropName = ";" + propName + "=";
+        int begIndex = url.indexOf(urlPropName);
+        if (begIndex >= 0) {
+            int endIndex = url.indexOf(';', begIndex + urlPropName.length());
+            if (endIndex < 0) {
+                endIndex = url.length();
+            }
+            String prefix = url.substring(0, begIndex);
+            String suffix = url.substring(endIndex, url.length());
+            return prefix + suffix;
+        } else {
+            return url;
+        }
+    }
+
     public static Long getCurrentSCN(String url, Properties info) throws SQLException {
         String scnStr = findProperty(url, info, PhoenixRuntime.CURRENT_SCN_ATTRIB);
         return (scnStr == null ? null : Long.parseLong(scnStr));

http://git-wip-us.apache.org/repos/asf/phoenix/blob/9833f072/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixDriverTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixDriverTest.java b/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixDriverTest.java
index bcb4f51..be40702 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixDriverTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixDriverTest.java
@@ -24,7 +24,6 @@ import java.sql.Connection;
 import java.sql.Driver;
 import java.sql.DriverManager;
 import java.sql.PreparedStatement;
-import java.sql.SQLException;
 import java.util.Properties;
 
 import org.apache.phoenix.query.BaseConnectionlessQueryTest;
@@ -37,10 +36,23 @@ public class PhoenixDriverTest extends BaseConnectionlessQueryTest {
 
     @Test
     public void testFirstConnectionWhenPropsHasTenantId() throws Exception {
-        final String url = getUrl();
-        verifyConnectionValid(url);
+        Properties props = new Properties();
+        final String tenantId = "00Dxx0000001234";
+        props.put(PhoenixRuntime.TENANT_ID_ATTRIB, tenantId);
+
+        Connection connection = new PhoenixTestDriver().connect(getUrl(), props);
+        assertEquals(tenantId, connection.getClientInfo(PhoenixRuntime.TENANT_ID_ATTRIB));
     }
-    
+
+    @Test
+    public void testFirstConnectionWhenUrlHasTenantId() throws Exception {
+        final String tenantId = "00Dxx0000001234";
+        String url = getUrl() + ";" + PhoenixRuntime.TENANT_ID_ATTRIB + "=" + tenantId;
+        Driver driver = new PhoenixTestDriver();
+
+        driver.connect(url, new Properties());
+    }
+
     @Test
     public void testMaxMutationSizeSetCorrectly() throws Exception {
         Properties connectionProperties = new Properties();
@@ -59,15 +71,4 @@ public class PhoenixDriverTest extends BaseConnectionlessQueryTest {
             fail("Upsert should have failed since the number of upserts (200) is greater
than the MAX_MUTATION_SIZE_ATTRIB (100)");
         } catch (IllegalArgumentException expected) {}
     }
-
-    private void verifyConnectionValid(String url) throws SQLException {
-        Driver driver = DriverManager.getDriver(url);
-
-        Properties props = new Properties();
-        final String tenantId = "00Dxx0000001234";
-        props.put(PhoenixRuntime.TENANT_ID_ATTRIB, tenantId);
-
-        Connection connection = driver.connect(url, props);
-        assertEquals(tenantId, connection.getClientInfo(PhoenixRuntime.TENANT_ID_ATTRIB));
-    }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/9833f072/phoenix-core/src/test/java/org/apache/phoenix/util/JDBCUtilTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/util/JDBCUtilTest.java b/phoenix-core/src/test/java/org/apache/phoenix/util/JDBCUtilTest.java
new file mode 100644
index 0000000..28e830b
--- /dev/null
+++ b/phoenix-core/src/test/java/org/apache/phoenix/util/JDBCUtilTest.java
@@ -0,0 +1,35 @@
+/**
+ * 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.phoenix.util;
+
+
+import static org.apache.phoenix.util.PhoenixRuntime.TENANT_ID_ATTRIB;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class JDBCUtilTest {
+    
+    @Test
+    public void testRemoveProperty() {
+        assertEquals("localhost;", JDBCUtil.removeProperty("localhost;TenantId=abc;", TENANT_ID_ATTRIB));
+        assertEquals("localhost;foo=bar", JDBCUtil.removeProperty("localhost;TenantId=abc;foo=bar",
TENANT_ID_ATTRIB));
+        assertEquals("localhost;TenantId=abc", JDBCUtil.removeProperty("localhost;TenantId=abc;foo=bar",
"foo"));
+        assertEquals("localhost;TenantId=abc;foo=bar", JDBCUtil.removeProperty("localhost;TenantId=abc;foo=bar",
"bar"));
+    }
+}


Mime
View raw message