Files
impala/tests/custom_cluster/test_concurrent_kudu_create.py
Joe McDonnell eb66d00f9f IMPALA-11974: Fix lazy list operators for Python 3 compatibility
Python 3 changes list operators such as range, map, and filter
to be lazy. Some code that expects the list operators to happen
immediately will fail. e.g.

Python 2:
range(0,5) == [0,1,2,3,4]
True

Python 3:
range(0,5) == [0,1,2,3,4]
False

The fix is to wrap locations with list(). i.e.

Python 3:
list(range(0,5)) == [0,1,2,3,4]
True

Since the base operators are now lazy, Python 3 also removes the
old lazy versions (e.g. xrange, ifilter, izip, etc). This uses
future's builtins package to convert the code to the Python 3
behavior (i.e. xrange -> future's builtins.range).

Most of the changes were done via these futurize fixes:
 - libfuturize.fixes.fix_xrange_with_import
 - lib2to3.fixes.fix_map
 - lib2to3.fixes.fix_filter

This eliminates the pylint warnings:
 - xrange-builtin
 - range-builtin-not-iterating
 - map-builtin-not-iterating
 - zip-builtin-not-iterating
 - filter-builtin-not-iterating
 - reduce-builtin
 - deprecated-itertools-function

Testing:
 - Ran core job

Change-Id: Ic7c082711f8eff451a1b5c085e97461c327edb5f
Reviewed-on: http://gerrit.cloudera.org:8080/19589
Reviewed-by: Joe McDonnell <joemcdonnell@cloudera.com>
Tested-by: Joe McDonnell <joemcdonnell@cloudera.com>
2023-03-09 17:17:57 +00:00

68 lines
2.5 KiB
Python

# 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.
from __future__ import absolute_import, division, print_function
from builtins import range
import pytest
import threading
import time
from multiprocessing.pool import ThreadPool
from tests.common.custom_cluster_test_suite import CustomClusterTestSuite
TBL_NAME = "test_concurrent_kudu_create"
class TestConcurrentKuduCreate(CustomClusterTestSuite):
"""Test concurrent create kudu managed table"""
@pytest.mark.execute_serially
def test_concurrent_create_kudu_table(self, unique_database):
table_name = unique_database + "." + TBL_NAME
test_self = self
class ThreadLocalClient(threading.local):
def __init__(self):
self.client = test_self.create_impala_client()
tls = ThreadLocalClient()
def run_create_table_if_not_exists():
self.execute_query_expect_success(
tls.client, "create table if not exists %s "
"(id int, primary key(id)) stored as kudu" % table_name)
# Drop table before run test if exists
self.execute_query("drop table if exists %s" % table_name)
NUM_ITERS = 20
pool = ThreadPool(processes=3)
for i in range(NUM_ITERS):
# Run several commands by specific time interval to reproduce this bug
r1 = pool.apply_async(run_create_table_if_not_exists)
r2 = pool.apply_async(run_create_table_if_not_exists)
# Sleep to make race conflict happens in different places
time.sleep(1)
r3 = pool.apply_async(run_create_table_if_not_exists)
r1.get()
r2.get()
r3.get()
# If hit IMPALA-8984, this query would be failed due to table been deleted in kudu
self.execute_query_expect_success(tls.client, "select * from %s" % table_name)
self.execute_query("drop table if exists %s" % table_name)
pool.terminate()