<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Licensed to Cloudera, Inc. under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  Cloudera, Inc. 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.
#

"""
Common infrastructure for beeswax tests
"""

import atexit
import logging
import pwd
import os
import re
import subprocess
import time

import fb303.ttypes
from nose.tools import assert_true, assert_false

from desktop.lib.django_test_util import make_logged_in_client

from hadoop import pseudo_hdfs4
import hadoop.conf

import beeswax.conf


_INITIALIZED = False
_SHARED_BEESWAX_SERVER_PROCESS = None
_SHARED_BEESWAX_SERVER = None
_SHARED_BEESWAX_SERVER_CLOSER = None

BEESWAXD_TEST_PORT = 6969
LOG = logging.getLogger(__name__)

def _start_server(cluster):
  """
  Start beeswaxd and metastore
  """
  script = beeswax.conf.BEESWAX_SERVER_BIN.get()
  args = [
    script,
    '--beeswax',
    str(BEESWAXD_TEST_PORT),
    '--metastore',
    str(BEESWAXD_TEST_PORT + 1),
    '--superuser',
    pwd.getpwuid(os.getuid())[0],
    '--desktop-host',
    str('127.0.0.1'),
    '--desktop-port',
    str('42'),           # Make up a port here. Tests don't start an actual server.
  ]

  env = cluster.mr1_env.copy()

  env.update({
    'HIVE_CONF_DIR': beeswax.conf.BEESWAX_HIVE_CONF_DIR.get(),
    'HIVE_HOME' : beeswax.conf.BEESWAX_HIVE_HOME_DIR.get(),
  })
  if os.getenv("JAVA_HOME"):
    env["JAVA_HOME"] = os.getenv("JAVA_HOME")

  LOG.info("Executing %s, env %s, cwd %s" % (repr(args), repr(env), cluster._tmpdir))
  process = subprocess.Popen(args=args, env=env, cwd=cluster._tmpdir, stdin=subprocess.PIPE)
  return process



def get_shared_beeswax_server():
  # Make it happens only once
  global _SHARED_BEESWAX_SERVER
  global _SHARED_BEESWAX_SERVER_CLOSER
  if _SHARED_BEESWAX_SERVER is None:
    # Copy hive-default.xml.template from BEESWAX_HIVE_CONF_DIR before it is set to
    # /my/bogus/path<commit_msg>[beeswax] Fix beeswax unit test (skip --superuser option)<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Licensed to Cloudera, Inc. under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  Cloudera, Inc. 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.
#

"""
Common infrastructure for beeswax tests
"""

import atexit
import logging
import pwd
import os
import re
import subprocess
import time

import fb303.ttypes
from nose.tools import assert_true, assert_false

from desktop.lib.django_test_util import make_logged_in_client

from hadoop import pseudo_hdfs4
import hadoop.conf

import beeswax.conf


_INITIALIZED = False
_SHARED_BEESWAX_SERVER_PROCESS = None
_SHARED_BEESWAX_SERVER = None
_SHARED_BEESWAX_SERVER_CLOSER = None

BEESWAXD_TEST_PORT = 6969
LOG = logging.getLogger(__name__)

def _start_server(cluster):
  """
  Start beeswaxd and metastore
  """
  script = beeswax.conf.BEESWAX_SERVER_BIN.get()
  args = [
    script,
    '--beeswax',
    str(BEESWAXD_TEST_PORT),
    '--metastore',
    str(BEESWAXD_TEST_PORT + 1),
    '--desktop-host',
    str('127.0.0.1'),
    '--desktop-port',
    str('42'),           # Make up a port here. Tests don't start an actual server.
  ]

  env = cluster.mr1_env.copy()

  env.update({
    'HIVE_CONF_DIR': beeswax.conf.BEESWAX_HIVE_CONF_DIR.get(),
    'HIVE_HOME' : beeswax.conf.BEESWAX_HIVE_HOME_DIR.get(),
  })
  if os.getenv("JAVA_HOME"):
    env["JAVA_HOME"] = os.getenv("JAVA_HOME")

  LOG.info("Executing %s, env %s, cwd %s" % (repr(args), repr(env), cluster._tmpdir))
  process = subprocess.Popen(args=args, env=env, cwd=cluster._tmpdir, stdin=subprocess.PIPE)
  return process



def get_shared_beeswax_server():
  # Make it happens only once
  global _SHARED_BEESWAX_SERVER
  global _SHARED_BEESWAX_SERVER_CLOSER
  if _SHARED_BEESWAX_SERVER is None:
    # Copy hive-default.xml.template from BEESWAX_HIVE_CONF_DIR before it is set to
    # /my/bogus/path
{'fraction_non_alphanumeric': 0.09801999607920016, 'fraction_numerical': 0.009213879631444814, 'mean_word_length': 4.163967611336032, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6798984', 'n_tokens_mistral': 1812, 'n_tokens_neox': 1748, 'n_words': 498}