phoenix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From samarthjain <...@git.apache.org>
Subject [GitHub] phoenix pull request: PHOENIX-1673 Allow TenantId to be of any int...
Date Fri, 07 Aug 2015 20:33:17 GMT
Github user samarthjain commented on a diff in the pull request:

    https://github.com/apache/phoenix/pull/104#discussion_r36558453
  
    --- Diff: phoenix-core/src/it/java/org/apache/phoenix/end2end/MultiTenantTableIT.java
---
    @@ -0,0 +1,140 @@
    +/*
    + * 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.end2end;
    +
    +import static org.junit.Assert.assertEquals;
    +import static org.junit.Assert.assertFalse;
    +import static org.junit.Assert.assertTrue;
    +import static org.junit.Assert.fail;
    +
    +import java.sql.*;
    +import java.util.Properties;
    +import java.util.Collection;
    +import java.util.List;
    +import com.google.common.collect.Lists;
    +
    +import org.apache.phoenix.exception.SQLExceptionCode;
    +import org.apache.phoenix.schema.TableAlreadyExistsException;
    +import org.apache.phoenix.util.PhoenixRuntime;
    +import org.junit.Test;
    +import org.junit.runner.RunWith;
    +import org.junit.runners.Parameterized;
    +import org.junit.runners.Parameterized.Parameters;
    +
    +@RunWith(Parameterized.class)
    +public class MultiTenantTableIT extends BaseClientManagedTimeIT {
    +
    +    private Connection regularConnection(String url) throws SQLException {
    +        Properties props = new Properties();
    +        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(nextTimestamp()));
    +        return DriverManager.getConnection(url, props);
    +    }
    +
    +    private Connection tenantConnection(String url) throws SQLException {
    +        Properties props = new Properties();
    +        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(nextTimestamp()));
    +        String tenantIdProperty = this.tenantId.replaceAll("\'", "");
    +        props.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB, tenantIdProperty);
    +        return DriverManager.getConnection(url, props);
    +    }
    +
    +    private final String ddl;
    +    private final String dataType;
    +    private final String tenantId;
    +    private final String otherTenantId;
    +    private final String table;
    +
    +    public MultiTenantTableIT( String dataType, String tenantId, String otherTenantId
) {
    +        this.dataType = dataType;
    +        this.tenantId = tenantId;
    +        this.otherTenantId = otherTenantId;
    +        String tbl = "foo" + dataType;
    +        if(tbl.contains("(")){
    +            tbl = tbl.substring(0, tbl.indexOf("("));
    +        }
    +        this.table = tbl;
    +        this.ddl = "create table " + table + " (" + "tid "+ dataType + " NOT NULL," +
"id INTEGER NOT NULL, \n"
    +                + "val VARCHAR " + "CONSTRAINT pk PRIMARY KEY(tid, id)) \n"
    +                + "MULTI_TENANT=true";
    +    }
    +
    +    @Parameters
    +    public static Collection<Object[]> data() {
    +        List<Object[]> testCases = Lists.newArrayList();
    +        testCases.add(new Object[] { "INTEGER", "2147483647", "2147483646" });
    +        testCases.add(new Object[] { "UNSIGNED_INT", "2147483647", "2147483646" });
    +        testCases.add(new Object[] { "BIGINT", "9223372036854775807", "9223372036854775806"
});
    +        testCases.add(new Object[] { "UNSIGNED_LONG", "9223372036854775807", "9223372036854775806"
});
    +        testCases.add(new Object[] { "TINYINT", "127", "126" });
    +        testCases.add(new Object[] { "UNSIGNED_TINYINT", "85", "84" });
    +        testCases.add(new Object[] { "SMALLINT", "32767", "32766" });
    +        testCases.add(new Object[] { "UNSIGNED_SMALLINT", "32767", "32766" });
    +        testCases.add(new Object[] { "FLOAT", "3.4028234", "3.4028232" });
    +        testCases.add(new Object[] { "UNSIGNED_FLOAT", "3.4028234", "3.4028232" });
    +        testCases.add(new Object[] { "DOUBLE", "1.7976931348623157", "1.7976931348623156"
});
    +        testCases.add(new Object[] { "UNSIGNED_DOUBLE", "1.7976931348623157", "1.7976931348623156"
});
    +        testCases.add(new Object[] { "DECIMAL", "3.402823466", "3.402823465" });
    +        testCases.add(new Object[] { "VARCHAR", "\'NameOfTenant\'", "\'Nemesis\'" });
    +        testCases.add(new Object[] { "CHAR(10)", "\'1234567890\'", "\'Nemesis\'" });
    +
    +        return testCases;
    +    }
    +
    +    @Test
    +    public void testMultiTenantTables() throws Exception {
    +        Connection conn = regularConnection(getUrl());
    +        conn.setAutoCommit(true);
    +        conn.createStatement().execute(ddl);
    +
    +
    +        try {
    +            conn.createStatement().execute(ddl);
    +            fail("Table with " + dataType + " tenantId not created correctly");
    +        } catch (TableAlreadyExistsException e) {
    +            // expected
    +        }
    +        conn.close();
    +        conn = regularConnection(getUrl());
    +        conn.setAutoCommit(true);
    +
    +        String query = "upsert into " + table +
    +                " values (" + tenantId + ", 1 , 'valid')";
    +
    +        conn.createStatement().execute("upsert into " + table +
    +                " values (" + tenantId + ", 1 , 'valid')");
    +        conn.createStatement().execute("upsert into " + table +
    +                " values (" + otherTenantId + ", 2 , 'invalid')");
    +
    +        Connection conn2 = tenantConnection(getUrl());
    --- End diff --
    
    Same as above - try-with-resources


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message