单元测试 Oozie 工作流
Unit Testing Oozie Workflows
我正在使用 Oozie 作为工具在 cloudera 平台上安排我的很多应用程序。 (火花、MR、Hive、HBase)。
我很担心的一件事是 Oozie 是一个无法测试的框架。
如果我使用 oozie 编写工作流。我如何对其进行单元测试?
是否有任何工具/最佳实践可以让我对 oozie 协调器和工作流执行自动化单元测试?
您可以使用 MiniOozie 对 Oozie 工作流进行单元测试。
这是 oozie 工作流的示例 junit 测试:
https://github.com/apache/oozie/blob/master/minitest/src/test/java/org/apache/oozie/test/TestWorkflow.java
使用 MiniOozieTestCase
:
构建测试时会遇到一些问题
确保您使用的 Oozie 版本包含 OOZIE-2273 的修复(已在 Oozie 4.3.0 中修复,但在 CDH 中向后移植到早期的 Oozie 版本)
确保登录用户名不包含.
这是因为用于从 Hadoop 配置构建代理用户 ACL 列表的正则表达式是:
hadoop\.proxyuser\.[^.]*(\Q.users\E|\Q.groups\E)
DefaultImpersonationProvider.java#L78
如果您的登录用户名包含 .
(例如 user.name
),当测试代码尝试访问 HDFS 时,您将收到以下错误:
org.apache.hadoop.security.authorize.AuthorizationException): User: user.name is not allowed to impersonate test
在这种情况下,您可以使用 HADOOP_USER_NAME
环境变量或通过设置系统 属性:
来覆盖登录用户名
public class IntTestCustomerModelLoaderJobWorkflow extends MiniOozieTestCase {
@Override
public void setUp() throws Exception {
System.setProperty("HADOOP_USER_NAME", "test");
}
...
}
您还需要在允许登录用户代理为测试用户的类路径中包含一个 hdfs-site.xml
。示例:
<?xml version="1.0"?>
<configuration>
<property>
<name>hadoop.proxyuser.test.groups</name>
<value>*</value>
<description>Allow the superuser test to impersonate any members of any group</description>
</property>
<property>
<name>hadoop.proxyuser.test.hosts</name>
<value>*</value>
<description>Allow the superuser test to connect from any host to impersonate a user</description>
</property>
</configuration>
在上面的示例中,登录用户名为 test
(与 test user used by MiniOozieTestCase
相同)。如果您愿意,可以使用不同的用户名。
我正在使用 Oozie 作为工具在 cloudera 平台上安排我的很多应用程序。 (火花、MR、Hive、HBase)。
我很担心的一件事是 Oozie 是一个无法测试的框架。
如果我使用 oozie 编写工作流。我如何对其进行单元测试?
是否有任何工具/最佳实践可以让我对 oozie 协调器和工作流执行自动化单元测试?
您可以使用 MiniOozie 对 Oozie 工作流进行单元测试。
这是 oozie 工作流的示例 junit 测试: https://github.com/apache/oozie/blob/master/minitest/src/test/java/org/apache/oozie/test/TestWorkflow.java
使用 MiniOozieTestCase
:
确保您使用的 Oozie 版本包含 OOZIE-2273 的修复(已在 Oozie 4.3.0 中修复,但在 CDH 中向后移植到早期的 Oozie 版本)
确保登录用户名不包含
.
这是因为用于从 Hadoop 配置构建代理用户 ACL 列表的正则表达式是:
hadoop\.proxyuser\.[^.]*(\Q.users\E|\Q.groups\E)
DefaultImpersonationProvider.java#L78
如果您的登录用户名包含 .
(例如 user.name
),当测试代码尝试访问 HDFS 时,您将收到以下错误:
org.apache.hadoop.security.authorize.AuthorizationException): User: user.name is not allowed to impersonate test
在这种情况下,您可以使用 HADOOP_USER_NAME
环境变量或通过设置系统 属性:
public class IntTestCustomerModelLoaderJobWorkflow extends MiniOozieTestCase {
@Override
public void setUp() throws Exception {
System.setProperty("HADOOP_USER_NAME", "test");
}
...
}
您还需要在允许登录用户代理为测试用户的类路径中包含一个 hdfs-site.xml
。示例:
<?xml version="1.0"?>
<configuration>
<property>
<name>hadoop.proxyuser.test.groups</name>
<value>*</value>
<description>Allow the superuser test to impersonate any members of any group</description>
</property>
<property>
<name>hadoop.proxyuser.test.hosts</name>
<value>*</value>
<description>Allow the superuser test to connect from any host to impersonate a user</description>
</property>
</configuration>
在上面的示例中,登录用户名为 test
(与 test user used by MiniOozieTestCase
相同)。如果您愿意,可以使用不同的用户名。