| OLD | NEW |
| 1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
| 2 # Copyright 2013 Google Inc. All Rights Reserved. | 2 # Copyright 2013 Google Inc. All Rights Reserved. |
| 3 # | 3 # |
| 4 # Licensed under the Apache License, Version 2.0 (the "License"); | 4 # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 # you may not use this file except in compliance with the License. | 5 # you may not use this file except in compliance with the License. |
| 6 # You may obtain a copy of the License at | 6 # You may obtain a copy of the License at |
| 7 # | 7 # |
| 8 # http://www.apache.org/licenses/LICENSE-2.0 | 8 # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 # | 9 # |
| 10 # Unless required by applicable law or agreed to in writing, software | 10 # Unless required by applicable law or agreed to in writing, software |
| 11 # distributed under the License is distributed on an "AS IS" BASIS, | 11 # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 # See the License for the specific language governing permissions and | 13 # See the License for the specific language governing permissions and |
| 14 # limitations under the License. | 14 # limitations under the License. |
| 15 """Integration tests for perfdiag command.""" | 15 """Integration tests for perfdiag command.""" |
| 16 | 16 |
| 17 from __future__ import absolute_import | 17 from __future__ import absolute_import |
| 18 | 18 |
| 19 import os | 19 import os |
| 20 import socket | 20 import socket |
| 21 | 21 |
| 22 import boto |
| 23 |
| 22 import gslib.tests.testcase as testcase | 24 import gslib.tests.testcase as testcase |
| 23 from gslib.tests.util import ObjectToURI as suri | 25 from gslib.tests.util import ObjectToURI as suri |
| 26 from gslib.tests.util import RUN_S3_TESTS |
| 24 from gslib.tests.util import unittest | 27 from gslib.tests.util import unittest |
| 25 from gslib.util import IS_WINDOWS | 28 from gslib.util import IS_WINDOWS |
| 26 | 29 |
| 27 | 30 |
| 28 class TestPerfDiag(testcase.GsUtilIntegrationTestCase): | 31 class TestPerfDiag(testcase.GsUtilIntegrationTestCase): |
| 29 """Integration tests for perfdiag command.""" | 32 """Integration tests for perfdiag command.""" |
| 30 | 33 |
| 31 # We want to test that perfdiag works both when connecting to the standard gs | 34 # We want to test that perfdiag works both when connecting to the standard gs |
| 32 # endpoint, and when connecting to a specific IP or host while setting the | 35 # endpoint, and when connecting to a specific IP or host while setting the |
| 33 # host header. For the 2nd case we resolve storage.googleapis.com to a | 36 # host header. For the 2nd case we resolve gs_host (normally |
| 34 # specific IP and connect to that explicitly. | 37 # storage.googleapis.com) to a specific IP and connect to that explicitly. |
| 35 _gs_ip = socket.gethostbyname('storage.googleapis.com') | 38 _gs_host = boto.config.get( |
| 39 'Credentials', 'gs_host', boto.gs.connection.GSConnection.DefaultHost) |
| 40 _gs_ip = socket.gethostbyname(_gs_host) |
| 36 _custom_endpoint_flags = [ | 41 _custom_endpoint_flags = [ |
| 37 '-o', 'Credentials:gs_host=' + _gs_ip, | 42 '-o', 'Credentials:gs_host=' + _gs_ip, |
| 38 '-o', 'Credentials:gs_host_header=storage.googleapis.com', | 43 '-o', 'Credentials:gs_host_header=' + _gs_host, |
| 39 # TODO: gsutil-beta: Add host header support for JSON | 44 # TODO: gsutil-beta: Add host header support for JSON |
| 40 '-o', 'Boto:https_validate_certificates=False'] | 45 '-o', 'Boto:https_validate_certificates=False'] |
| 41 | 46 |
| 42 def _should_run_with_custom_endpoints(self): | 47 def _should_run_with_custom_endpoints(self): |
| 43 # Host headers are only supported for XML, and not when | 48 # Host headers are only supported for XML, and not when |
| 44 # using environment variables for proxies. | 49 # using environment variables for proxies. |
| 45 return self.test_api == 'XML' and not (os.environ.get('http_proxy') or | 50 return (self.test_api == 'XML' and not RUN_S3_TESTS and not |
| 46 os.environ.get('https_proxy') or | 51 (os.environ.get('http_proxy') or os.environ.get('https_proxy') or |
| 47 os.environ.get('HTTPS_PROXY')) | 52 os.environ.get('HTTPS_PROXY'))) |
| 48 | 53 |
| 49 def test_latency(self): | 54 def test_latency(self): |
| 50 bucket_uri = self.CreateBucket() | 55 bucket_uri = self.CreateBucket() |
| 51 cmd = ['perfdiag', '-n', '1', '-t', 'lat', suri(bucket_uri)] | 56 cmd = ['perfdiag', '-n', '1', '-t', 'lat', suri(bucket_uri)] |
| 52 self.RunGsUtil(cmd) | 57 self.RunGsUtil(cmd) |
| 53 if self._should_run_with_custom_endpoints(): | 58 if self._should_run_with_custom_endpoints(): |
| 54 self.RunGsUtil(self._custom_endpoint_flags + cmd) | 59 self.RunGsUtil(self._custom_endpoint_flags + cmd) |
| 55 self.AssertNObjectsInBucket(bucket_uri, 0, versioned=True) | 60 self.AssertNObjectsInBucket(bucket_uri, 0, versioned=True) |
| 56 | 61 |
| 57 def _run_basic_wthru_or_rthru(self, test_name, num_processes, num_threads): | 62 def _run_throughput_test(self, test_name, num_processes, num_threads, |
| 63 parallelism_strategy=None): |
| 58 bucket_uri = self.CreateBucket() | 64 bucket_uri = self.CreateBucket() |
| 65 |
| 59 cmd = ['perfdiag', '-n', str(num_processes * num_threads), | 66 cmd = ['perfdiag', '-n', str(num_processes * num_threads), |
| 60 '-s', '1024', '-c', str(num_processes), | 67 '-s', '1024', '-c', str(num_processes), '-k', str(num_threads), |
| 61 '-k', str(num_threads), '-t', test_name, suri(bucket_uri)] | 68 '-t', test_name] |
| 69 if parallelism_strategy: |
| 70 cmd += ['-p', parallelism_strategy] |
| 71 cmd += [suri(bucket_uri)] |
| 72 |
| 62 self.RunGsUtil(cmd) | 73 self.RunGsUtil(cmd) |
| 63 if self._should_run_with_custom_endpoints(): | 74 if self._should_run_with_custom_endpoints(): |
| 64 self.RunGsUtil(self._custom_endpoint_flags + cmd) | 75 self.RunGsUtil(self._custom_endpoint_flags + cmd) |
| 65 self.AssertNObjectsInBucket(bucket_uri, 0, versioned=True) | 76 self.AssertNObjectsInBucket(bucket_uri, 0, versioned=True) |
| 66 | 77 |
| 78 def _run_each_parallel_throughput_test(self, test_name, num_processes, |
| 79 num_threads): |
| 80 self._run_throughput_test(test_name, num_processes, num_threads, 'fan') |
| 81 if not RUN_S3_TESTS: |
| 82 self._run_throughput_test(test_name, num_processes, num_threads, 'slice') |
| 83 self._run_throughput_test(test_name, num_processes, num_threads, 'both') |
| 84 |
| 67 def test_write_throughput_single_process_single_thread(self): | 85 def test_write_throughput_single_process_single_thread(self): |
| 68 self._run_basic_wthru_or_rthru('wthru', 1, 1) | 86 self._run_throughput_test('wthru', 1, 1) |
| 87 self._run_throughput_test('wthru_file', 1, 1) |
| 69 | 88 |
| 70 def test_write_throughput_single_process_multi_thread(self): | 89 def test_write_throughput_single_process_multi_thread(self): |
| 71 self._run_basic_wthru_or_rthru('wthru', 1, 2) | 90 self._run_each_parallel_throughput_test('wthru', 1, 2) |
| 91 self._run_each_parallel_throughput_test('wthru_file', 1, 2) |
| 72 | 92 |
| 73 @unittest.skipIf(IS_WINDOWS, 'Multiprocessing is not supported on Windows') | 93 @unittest.skipIf(IS_WINDOWS, 'Multiprocessing is not supported on Windows') |
| 74 def test_write_throughput_multi_process_single_thread(self): | 94 def test_write_throughput_multi_process_single_thread(self): |
| 75 self._run_basic_wthru_or_rthru('wthru', 2, 1) | 95 self._run_each_parallel_throughput_test('wthru', 2, 1) |
| 96 self._run_each_parallel_throughput_test('wthru_file', 2, 1) |
| 76 | 97 |
| 77 @unittest.skipIf(IS_WINDOWS, 'Multiprocessing is not supported on Windows') | 98 @unittest.skipIf(IS_WINDOWS, 'Multiprocessing is not supported on Windows') |
| 78 def test_write_throughput_multi_process_multi_thread(self): | 99 def test_write_throughput_multi_process_multi_thread(self): |
| 79 self._run_basic_wthru_or_rthru('wthru', 2, 2) | 100 self._run_each_parallel_throughput_test('wthru', 2, 2) |
| 101 self._run_each_parallel_throughput_test('wthru_file', 2, 2) |
| 80 | 102 |
| 81 def test_read_throughput_single_process_single_thread(self): | 103 def test_read_throughput_single_process_single_thread(self): |
| 82 self._run_basic_wthru_or_rthru('rthru', 1, 1) | 104 self._run_throughput_test('rthru', 1, 1) |
| 105 self._run_throughput_test('rthru_file', 1, 1) |
| 83 | 106 |
| 84 def test_read_throughput_single_process_multi_thread(self): | 107 def test_read_throughput_single_process_multi_thread(self): |
| 85 self._run_basic_wthru_or_rthru('rthru', 1, 2) | 108 self._run_each_parallel_throughput_test('rthru', 1, 2) |
| 109 self._run_each_parallel_throughput_test('rthru_file', 1, 2) |
| 86 | 110 |
| 87 @unittest.skipIf(IS_WINDOWS, 'Multiprocessing is not supported on Windows') | 111 @unittest.skipIf(IS_WINDOWS, 'Multiprocessing is not supported on Windows') |
| 88 def test_read_throughput_multi_process_single_thread(self): | 112 def test_read_throughput_multi_process_single_thread(self): |
| 89 self._run_basic_wthru_or_rthru('rthru', 2, 1) | 113 self._run_each_parallel_throughput_test('rthru', 2, 1) |
| 114 self._run_each_parallel_throughput_test('rthru_file', 2, 1) |
| 90 | 115 |
| 91 @unittest.skipIf(IS_WINDOWS, 'Multiprocessing is not supported on Windows') | 116 @unittest.skipIf(IS_WINDOWS, 'Multiprocessing is not supported on Windows') |
| 92 def test_read_throughput_multi_process_multi_thread(self): | 117 def test_read_throughput_multi_process_multi_thread(self): |
| 93 self._run_basic_wthru_or_rthru('rthru', 2, 2) | 118 self._run_each_parallel_throughput_test('rthru', 2, 2) |
| 119 self._run_each_parallel_throughput_test('rthru_file', 2, 2) |
| 120 |
| 121 @unittest.skipIf(IS_WINDOWS, 'Multiprocessing is not supported on Windows') |
| 122 def test_read_and_write_file_ordering(self): |
| 123 """Tests that rthru_file and wthru_file work when run together.""" |
| 124 self._run_throughput_test('rthru_file,wthru_file', 1, 1) |
| 125 self._run_throughput_test('rthru_file,wthru_file', 2, 2, 'fan') |
| 126 if not RUN_S3_TESTS: |
| 127 self._run_throughput_test('rthru_file,wthru_file', 2, 2, 'slice') |
| 128 self._run_throughput_test('rthru_file,wthru_file', 2, 2, 'both') |
| 94 | 129 |
| 95 def test_input_output(self): | 130 def test_input_output(self): |
| 96 outpath = self.CreateTempFile() | 131 outpath = self.CreateTempFile() |
| 97 bucket_uri = self.CreateBucket() | 132 bucket_uri = self.CreateBucket() |
| 98 self.RunGsUtil(['perfdiag', '-o', outpath, '-n', '1', '-t', 'lat', | 133 self.RunGsUtil(['perfdiag', '-o', outpath, '-n', '1', '-t', 'lat', |
| 99 suri(bucket_uri)]) | 134 suri(bucket_uri)]) |
| 100 self.RunGsUtil(['perfdiag', '-i', outpath]) | 135 self.RunGsUtil(['perfdiag', '-i', outpath]) |
| 101 | 136 |
| 102 def test_invalid_size(self): | 137 def test_invalid_size(self): |
| 103 stderr = self.RunGsUtil( | 138 stderr = self.RunGsUtil( |
| 104 ['perfdiag', '-n', '1', '-s', 'foo', '-t', 'wthru', 'gs://foobar'], | 139 ['perfdiag', '-n', '1', '-s', 'foo', '-t', 'wthru', 'gs://foobar'], |
| 105 expected_status=1, return_stderr=True) | 140 expected_status=1, return_stderr=True) |
| 106 self.assertIn('Invalid -s', stderr) | 141 self.assertIn('Invalid -s', stderr) |
| 107 | 142 |
| 108 def test_toobig_size(self): | 143 def test_toobig_size(self): |
| 109 stderr = self.RunGsUtil( | 144 stderr = self.RunGsUtil( |
| 110 ['perfdiag', '-n', '1', '-s', '3pb', '-t', 'wthru', 'gs://foobar'], | 145 ['perfdiag', '-n', '1', '-s', '3pb', '-t', 'wthru', 'gs://foobar'], |
| 111 expected_status=1, return_stderr=True) | 146 expected_status=1, return_stderr=True) |
| 112 self.assertIn('Maximum throughput file size', stderr) | 147 self.assertIn('in-memory tests maximum file size', stderr) |
| 113 | 148 |
| 114 def test_listing(self): | 149 def test_listing(self): |
| 115 bucket_uri = self.CreateBucket() | 150 bucket_uri = self.CreateBucket() |
| 116 stdout = self.RunGsUtil( | 151 stdout = self.RunGsUtil( |
| 117 ['perfdiag', '-n', '1', '-t', 'list', suri(bucket_uri)], | 152 ['perfdiag', '-n', '1', '-t', 'list', suri(bucket_uri)], |
| 118 return_stdout=True) | 153 return_stdout=True) |
| 119 self.assertIn('Number of listing calls made:', stdout) | 154 self.assertIn('Number of listing calls made:', stdout) |
| 120 self.AssertNObjectsInBucket(bucket_uri, 0, versioned=True) | 155 self.AssertNObjectsInBucket(bucket_uri, 0, versioned=True) |
| OLD | NEW |