Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into deepseek
Browse files Browse the repository at this point in the history
  • Loading branch information
lhpqaq committed Jan 26, 2025
2 parents 79de73d + 2141ba9 commit e6b344a
Show file tree
Hide file tree
Showing 14 changed files with 829 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ public void onMessage(ReqT message) {
if (isTaskRequest(message)) {
try {
Method method = message.getClass().getDeclaredMethod("getTaskId");
method.setAccessible(true);
Long taskId = (Long) method.invoke(message);
method.setAccessible(false);
truncateLogFile(taskId);
MDC.put("taskId", String.valueOf(taskId));
Caches.RUNNING_TASK = taskId;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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.ai.core.enums;

import org.junit.jupiter.api.Test;

import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class MessageTypeTest {

@Test
public void testGetSenders() {
List<String> senders = MessageType.getSenders();
assertEquals(3, senders.size());
assertTrue(senders.contains("user"));
assertTrue(senders.contains("ai"));
assertTrue(senders.contains("system"));
}

@Test
public void testGetMessageSender() {
assertEquals(MessageType.USER, MessageType.getMessageSender("user"));
assertEquals(MessageType.AI, MessageType.getMessageSender("ai"));
assertEquals(MessageType.SYSTEM, MessageType.getMessageSender("system"));
assertNull(MessageType.getMessageSender(""));
assertNull(MessageType.getMessageSender(null));
assertNull(MessageType.getMessageSender("unknown"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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.ai.core.enums;

import org.junit.jupiter.api.Test;

import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class PlatformTypeTest {

@Test
public void testGetPlatforms() {
List<String> senders = PlatformType.getPlatforms();
assertEquals(3, senders.size());
assertTrue(senders.contains("openai"));
assertTrue(senders.contains("dashscope"));
assertTrue(senders.contains("qianfan"));
}

@Test
public void testGetPlatformType() {
assertEquals(PlatformType.OPENAI, PlatformType.getPlatformType("openai"));
assertEquals(PlatformType.DASH_SCOPE, PlatformType.getPlatformType("dashscope"));
assertEquals(PlatformType.QIANFAN, PlatformType.getPlatformType("qianfan"));
assertNull(PlatformType.getPlatformType(""));
assertNull(PlatformType.getPlatformType(null));
assertNull(PlatformType.getPlatformType("unknown"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
/*
* 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.common.enums;

import org.junit.jupiter.api.Test;

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

public class CommandTest {

// Test normal path: verify that the code and name of enum values are correct
@Test
public void testCommandNormalPath() {
assertEquals("add", Command.ADD.getCode(), "The code of ADD should be 'add'");
assertEquals("Add", Command.ADD.getName(), "The name of ADD should be 'Add'");

assertEquals("start", Command.START.getCode(), "The code of START should be 'start'");
assertEquals("Start", Command.START.getName(), "The name of START should be 'Start'");

assertEquals("stop", Command.STOP.getCode(), "The code of STOP should be 'stop'");
assertEquals("Stop", Command.STOP.getName(), "The name of STOP should be 'Stop'");

assertEquals("restart", Command.RESTART.getCode(), "The code of RESTART should be 'restart'");
assertEquals("Restart", Command.RESTART.getName(), "The name of RESTART should be 'Restart'");

assertEquals("check", Command.CHECK.getCode(), "The code of CHECK should be 'check'");
assertEquals("Check", Command.CHECK.getName(), "The name of CHECK should be 'Check'");

assertEquals("configure", Command.CONFIGURE.getCode(), "The code of CONFIGURE should be 'configure'");
assertEquals("Configure", Command.CONFIGURE.getName(), "The name of CONFIGURE should be 'Configure'");

assertEquals("custom", Command.CUSTOM.getCode(), "The code of CUSTOM should be 'custom'");
assertEquals("Custom", Command.CUSTOM.getName(), "The name of CUSTOM should be 'Custom'");

assertEquals("init", Command.INIT.getCode(), "The code of INIT should be 'init'");
assertEquals("Init", Command.INIT.getName(), "The name of INIT should be 'Init'");

assertEquals("prepare", Command.PREPARE.getCode(), "The code of PREPARE should be 'prepare'");
assertEquals("Prepare", Command.PREPARE.getName(), "The name of PREPARE should be 'Prepare'");

assertEquals("status", Command.STATUS.getCode(), "The code of STATUS should be 'status'");
assertEquals("Status", Command.STATUS.getName(), "The name of STATUS should be 'Status'");
}

// Test boundary conditions: verify that the fromString method can correctly convert strings in upper case, lower
// case, and mixed case
@Test
public void testFromStringWithVariousCases() {
assertEquals(Command.ADD, Command.fromString("ADD"), "Upper case 'ADD' should be converted to ADD enum value");
assertEquals(Command.ADD, Command.fromString("add"), "Lower case 'add' should be converted to ADD enum value");
assertEquals(Command.ADD, Command.fromString("AdD"), "Mixed case 'AdD' should be converted to ADD enum value");

assertEquals(
Command.START,
Command.fromString("START"),
"Upper case 'START' should be converted to START enum value");
assertEquals(
Command.START,
Command.fromString("start"),
"Lower case 'start' should be converted to START enum value");
assertEquals(
Command.START,
Command.fromString("StArT"),
"Mixed case 'StArT' should be converted to START enum value");

assertEquals(
Command.STOP, Command.fromString("STOP"), "Upper case 'STOP' should be converted to STOP enum value");
assertEquals(
Command.STOP, Command.fromString("stop"), "Lower case 'stop' should be converted to STOP enum value");
assertEquals(
Command.STOP, Command.fromString("StOp"), "Mixed case 'StOp' should be converted to STOP enum value");

assertEquals(
Command.RESTART,
Command.fromString("RESTART"),
"Upper case 'RESTART' should be converted to RESTART enum value");
assertEquals(
Command.RESTART,
Command.fromString("restart"),
"Lower case 'restart' should be converted to RESTART enum value");
assertEquals(
Command.RESTART,
Command.fromString("ReStArT"),
"Mixed case 'ReStArT' should be converted to RESTART enum value");

assertEquals(
Command.CHECK,
Command.fromString("CHECK"),
"Upper case 'CHECK' should be converted to CHECK enum value");
assertEquals(
Command.CHECK,
Command.fromString("check"),
"Lower case 'check' should be converted to CHECK enum value");
assertEquals(
Command.CHECK,
Command.fromString("ChEcK"),
"Mixed case 'ChEcK' should be converted to CHECK enum value");

assertEquals(
Command.CONFIGURE,
Command.fromString("CONFIGURE"),
"Upper case 'CONFIGURE' should be converted to CONFIGURE enum value");
assertEquals(
Command.CONFIGURE,
Command.fromString("configure"),
"Lower case 'configure' should be converted to CONFIGURE enum value");
assertEquals(
Command.CONFIGURE,
Command.fromString("CoNfIgUrE"),
"Mixed case 'CoNfIgUrE' should be converted to CONFIGURE enum value");

assertEquals(
Command.CUSTOM,
Command.fromString("CUSTOM"),
"Upper case 'CUSTOM' should be converted to CUSTOM enum value");
assertEquals(
Command.CUSTOM,
Command.fromString("custom"),
"Lower case 'custom' should be converted to CUSTOM enum value");
assertEquals(
Command.CUSTOM,
Command.fromString("CuStOm"),
"Mixed case 'CuStOm' should be converted to CUSTOM enum value");

assertEquals(
Command.INIT, Command.fromString("INIT"), "Upper case 'INIT' should be converted to INIT enum value");
assertEquals(
Command.INIT, Command.fromString("init"), "Lower case 'init' should be converted to INIT enum value");
assertEquals(
Command.INIT, Command.fromString("InIt"), "Mixed case 'InIt' should be converted to INIT enum value");

assertEquals(
Command.PREPARE,
Command.fromString("PREPARE"),
"Upper case 'PREPARE' should be converted to PREPARE enum value");
assertEquals(
Command.PREPARE,
Command.fromString("prepare"),
"Lower case 'prepare' should be converted to PREPARE enum value");
assertEquals(
Command.PREPARE,
Command.fromString("PrEpArE"),
"Mixed case 'PrEpArE' should be converted to PREPARE enum value");

assertEquals(
Command.STATUS,
Command.fromString("STATUS"),
"Upper case 'STATUS' should be converted to STATUS enum value");
assertEquals(
Command.STATUS,
Command.fromString("status"),
"Lower case 'status' should be converted to STATUS enum value");
assertEquals(
Command.STATUS,
Command.fromString("StAtUs"),
"Mixed case 'StAtUs' should be converted to STATUS enum value");
}

// Test boundary conditions: verify that the fromString method throws an exception when passed an invalid string
@Test
public void testFromStringWithInvalidString() {
assertThrows(
IllegalArgumentException.class,
() -> Command.fromString("INVALID"),
"Passing invalid string 'INVALID' should throw an IllegalArgumentException");
assertThrows(
IllegalArgumentException.class,
() -> Command.fromString(""),
"Passing empty string '' should throw an IllegalArgumentException");
assertThrows(
NullPointerException.class,
() -> Command.fromString(null),
"Passing null should throw a NullPointerException");
}

// Test boundary conditions: verify that the toCamelCase method can correctly convert enum values to camel case
// strings
@Test
public void testToCamelCase() {
assertEquals("Add", Command.ADD.toCamelCase(), "ADD should be converted to 'Add'");
assertEquals("Start", Command.START.toCamelCase(), "START should be converted to 'Start'");
assertEquals("Stop", Command.STOP.toCamelCase(), "STOP should be converted to 'Stop'");
assertEquals("Restart", Command.RESTART.toCamelCase(), "RESTART should be converted to 'Restart'");
assertEquals("Check", Command.CHECK.toCamelCase(), "CHECK should be converted to 'Check'");
assertEquals("Configure", Command.CONFIGURE.toCamelCase(), "CONFIGURE should be converted to 'Configure'");
assertEquals("Custom", Command.CUSTOM.toCamelCase(), "CUSTOM should be converted to 'Custom'");
assertEquals("Init", Command.INIT.toCamelCase(), "INIT should be converted to 'Init'");
assertEquals("Prepare", Command.PREPARE.toCamelCase(), "PREPARE should be converted to 'Prepare'");
assertEquals("Status", Command.STATUS.toCamelCase(), "STATUS should be converted to 'Status'");
}
}
Loading

0 comments on commit e6b344a

Please sign in to comment.