Skip to content

Commit

Permalink
BIGTOP-4348: Add some unit tests for stack bigtop module (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
xianrenzw authored Feb 13, 2025
1 parent 9cf142b commit 788c3b4
Show file tree
Hide file tree
Showing 32 changed files with 1,956 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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
*
* https://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.bigtop.manager.stack.bigtop.v3_3_0.flink;

import org.apache.bigtop.manager.stack.core.spi.param.Params;

import org.junit.jupiter.api.Test;

import lombok.extern.slf4j.Slf4j;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

@Slf4j
public class FlinkClientScriptTest {

private final FlinkClientScript flinkClientScript = new FlinkClientScript();

@Test
public void testGetComponentName() {
assertEquals("flink_client", flinkClientScript.getComponentName());
}

@Test
public void testAddParamsNull() {
Params params = null;
assertThrows(NullPointerException.class, () -> flinkClientScript.add(params));
}

@Test
public void testConfigureParamsNull() {
Params params = null;
assertThrows(NullPointerException.class, () -> flinkClientScript.configure(params));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* 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
*
* https://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.bigtop.manager.stack.bigtop.v3_3_0.flink;

import org.apache.bigtop.manager.stack.core.spi.param.Params;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

class FlinkHistoryServerScriptTest {

private final FlinkHistoryServerScript flinkHistoryServerScript = new FlinkHistoryServerScript();

@Test
void testGetComponentName() {
assertEquals("flink_historyserver", flinkHistoryServerScript.getComponentName());
}

@Test
public void testAddParamsNull() {
Params params = null;
assertThrows(NullPointerException.class, () -> flinkHistoryServerScript.add(params));
}

@Test
public void testConfigureParamsNull() {
Params params = null;
assertThrows(NullPointerException.class, () -> flinkHistoryServerScript.configure(params));
}

@Test
public void testStartParamsNull() {
Params params = null;
assertThrows(NullPointerException.class, () -> flinkHistoryServerScript.start(params));
}

@Test
public void testStopParamsNull() {
Params params = null;
assertThrows(NullPointerException.class, () -> flinkHistoryServerScript.stop(params));
}

@Test
public void testStatusParamsNull() {
Params params = null;
assertThrows(NullPointerException.class, () -> flinkHistoryServerScript.status(params));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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
*
* https://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.bigtop.manager.stack.bigtop.v3_3_0.flink;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class FlinkParamsTest {

private FlinkParams flinkParams;

@BeforeEach
public void setUp() {
flinkParams = mock(FlinkParams.class);
when(flinkParams.stackHome()).thenReturn("/stack");
when(flinkParams.getServiceName()).thenCallRealMethod();
when(flinkParams.serviceHome()).thenCallRealMethod();
when(flinkParams.hadoopHome()).thenCallRealMethod();
when(flinkParams.hadoopConfDir()).thenCallRealMethod();
when(flinkParams.confDir()).thenCallRealMethod();
}

@Test
public void testServiceHome() {
assertEquals("/stack/flink", flinkParams.serviceHome());
}

@Test
public void testConfDir() {
assertEquals("/stack/flink/conf", flinkParams.confDir());
}

@Test
public void testHadoopConfDir() {
assertEquals("/stack/hadoop/etc/hadoop", flinkParams.hadoopConfDir());
}

@Test
public void testHadoopHome() {
assertEquals("/stack/hadoop", flinkParams.hadoopHome());
}

@Test
public void testGetServiceName() {
assertEquals("flink", flinkParams.getServiceName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* 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
*
* https://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.bigtop.manager.stack.bigtop.v3_3_0.hadoop;

import org.apache.bigtop.manager.stack.core.spi.param.Params;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class DataNodeScriptTest {

private final DataNodeScript dataNodeScript = new DataNodeScript();

@Test
public void testGetComponentName() {
assertEquals("datanode", dataNodeScript.getComponentName());
}

@Test
public void testAddParamsNull() {
Params params = null;
assertThrows(NullPointerException.class, () -> dataNodeScript.add(params));
}

@Test
public void testConfigureParamsNull() {
Params params = null;
assertThrows(NullPointerException.class, () -> dataNodeScript.configure(params));
}

@Test
public void testStartParamsNull() {
Params params = null;
assertThrows(NullPointerException.class, () -> dataNodeScript.start(params));
}

@Test
public void testStopParamsNull() {
Params params = null;
assertThrows(NullPointerException.class, () -> dataNodeScript.stop(params));
}

@Test
public void testStatusParamsNull() {
Params params = null;
assertThrows(NullPointerException.class, () -> dataNodeScript.status(params));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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
*
* https://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.bigtop.manager.stack.bigtop.v3_3_0.hadoop;

import org.junit.jupiter.api.Test;

import lombok.extern.slf4j.Slf4j;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

@Slf4j
public class HadoopClientScriptTest {

private final HadoopClientScript hadoopClientScript = new HadoopClientScript();

@Test
public void testGetComponentName() {
assertEquals("hadoop_client", hadoopClientScript.getComponentName());
}

@Test
public void testAddParamsNull() {
assertThrows(NullPointerException.class, () -> hadoopClientScript.add(null));
}

@Test
public void testConfigureParamsNull() {
assertThrows(NullPointerException.class, () -> hadoopClientScript.configure(null));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* 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
*
* https://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.bigtop.manager.stack.bigtop.v3_3_0.hadoop;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class HadoopParamsTest {

private HadoopParams hadoopParams;

@BeforeEach
public void setUp() {
hadoopParams = mock(HadoopParams.class);
when(hadoopParams.stackHome()).thenReturn("/stack");
when(hadoopParams.getServiceName()).thenCallRealMethod();
when(hadoopParams.serviceHome()).thenCallRealMethod();
when(hadoopParams.confDir()).thenCallRealMethod();
when(hadoopParams.binDir()).thenCallRealMethod();
}

@Test
public void testServiceHome() {
assertEquals("/stack/hadoop", hadoopParams.serviceHome());
}

@Test
public void testConfDir() {
assertEquals("/stack/hadoop/etc/hadoop", hadoopParams.confDir());
}

@Test
public void testBinDir() {
assertEquals("/stack/hadoop/bin", hadoopParams.binDir());
}

@Test
public void testGetServiceName() {
assertEquals("hadoop", hadoopParams.getServiceName());
}
}
Loading

0 comments on commit 788c3b4

Please sign in to comment.