Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@
(select resource_id from linkis_cg_manager_label_resource A join linkis_cg_manager_label_service_instance B on A.label_id=B.label_id and B.service_instance = #{instance} )
</delete>
<delete id="deleteResourceByTicketId">
select * from linkis_cg_manager_linkis_resources where resourceType = #{resourceType} and
id in (select resource_id from linkis_cg_manager_label_resource A join linkis_cg_manager_label_service_instance B on A.label_id = B.label_id and B.service_instance=#{instance})
delete from linkis_cg_manager_linkis_resources where ticketId = #{ticketId}
</delete>

<select id="getResourceByServiceInstance" resultType="org.apache.linkis.manager.common.entity.persistence.PersistenceResource">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,14 @@ void deleteResourceByInstance() {
@Test
void deleteResourceByTicketId() {
registerResource();
PersistenceResource otherResource = new PersistenceResource();
otherResource.setId(2);
otherResource.setTicketId("2");
resourceManagerMapper.registerResource(otherResource);
resourceManagerMapper.deleteResourceByTicketId("1");
PersistenceResource persistenceResource = resourceManagerMapper.getNodeResourceByTicketId("1");
assertTrue(persistenceResource == null);
assertTrue(resourceManagerMapper.getNodeResourceByTicketId("2") != null);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
status = #{targetStatus}
</set>
<where>
<foreach collection="list" index="index" item="element" close=")" separator="," open="id in (">
<foreach collection="idList" index="index" item="element" close=")" separator="," open="id in (">
#{element}
</foreach>
</where>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,11 @@
</select>

<select id="maxID" useCache="true" resultType="java.lang.Integer" >
/*slave*/ SELECT id FROM linkis_ps_job_history_group_history
/*slave*/ SELECT MAX(id) FROM linkis_ps_job_history_group_history
<where>
<if test="startDate != null">and created_time >= #{startDate} AND created_time <![CDATA[<=]]> #{endDate}</if>
<if test="startId != null">and id >= #{startId}</if>
</where>
ORDER BY linkis_ps_job_history_group_history.created_time
</select>

<select id="searchWithUserCreator" useCache="true" resultMap="jobHistoryMap" >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,23 @@
ORDER BY linkis_ps_job_history_group_history.created_time DESC
</select>

<select id="searchWithIdOrderAsc" useCache="true" resultMap="jobHistoryMap" >
/*slave*/ SELECT * FROM linkis_ps_job_history_group_history
<select id="searchWithIdOrderAsc" useCache="true" resultType="java.lang.Integer" >
/*slave*/ SELECT id FROM linkis_ps_job_history_group_history
<where>
<if test="id != null">id >= #{id}</if>
<if test="umUser != null">and submit_user = #{umUser}</if>
<if test="engineType != null">and engine_type = #{engineType}</if>
<if test="startDate != null">and created_time >= #{startDate} AND created_time <![CDATA[<=]]> #{endDate}</if>
<if test="startId != null">and id >= #{startId}</if>
<if test="status != null">and <foreach collection="status" item="element" close=")" separator="," open="status in (">#{element}</foreach></if>
</where>
ORDER BY linkis_ps_job_history_group_history.id
LIMIT 2
</select>

<select id="maxID" useCache="true" resultType="java.lang.Integer" >
/*slave*/ SELECT MAX(id) FROM linkis_ps_job_history_group_history
<where>
<if test="startDate != null">and created_time >= #{startDate} AND created_time <![CDATA[<=]]> #{endDate}</if>
<if test="startId != null">and id >= #{startId}</if>
</where>
</select>

<select id="searchWithUserCreator" useCache="true" resultMap="jobHistoryMap" >
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* 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
*
* 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.
*/

package org.apache.linkis.jobhistory.dao;

import org.apache.ibatis.builder.xml.XMLMapperBuilder;
import org.apache.ibatis.datasource.unpooled.UnpooledDataSource;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.mapping.Environment;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;

import java.io.InputStream;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

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

/**
* Covers the queries used by {@code DefaultQueryCacheManager#refreshUndoneTask} with both the MySQL
* and the PostgreSQL mapper. The Spring based DAO tests only load the MySQL mapper, so a plain
* MyBatis session is used here.
*/
class JobHistoryMapperUndoneTaskTest {

private static final Date START = Timestamp.valueOf("2026-01-01 00:00:00");
private static final Date END = Timestamp.valueOf("2026-01-02 00:00:00");

@Test
void searchWithIdOrderAscOnPostgresql() throws Exception {
try (SqlSession session = openSession("postgresql", "PostgreSQL")) {
List<Integer> ids =
session
.getMapper(JobHistoryMapper.class)
.searchWithIdOrderAsc(
START, END, 3L, Arrays.asList("Running", "Inited", "Scheduled"));
assertEquals(Arrays.asList(4, 5), ids);
}
}

@ParameterizedTest
@CsvSource({"mysql, MySQL", "postgresql, PostgreSQL"})
void maxID(String dialect, String h2Mode) throws Exception {
try (SqlSession session = openSession(dialect, h2Mode)) {
assertEquals(
Integer.valueOf(6), session.getMapper(JobHistoryMapper.class).maxID(START, END, 3L));
}
}

private static SqlSession openSession(String dialect, String h2Mode) throws Exception {
UnpooledDataSource dataSource =
new UnpooledDataSource(
"org.h2.Driver", "jdbc:h2:mem:" + dialect + ";MODE=" + h2Mode, "sa", "");
Configuration configuration =
new Configuration(new Environment("test", new JdbcTransactionFactory(), dataSource));
String resource = "mapper/" + dialect + "/JobHistoryMapper.xml";
try (InputStream input = Resources.getResourceAsStream(resource)) {
new XMLMapperBuilder(input, configuration, resource, configuration.getSqlFragments()).parse();
}
SqlSession session = new SqlSessionFactoryBuilder().build(configuration).openSession(true);
try (Statement statement = session.getConnection().createStatement()) {
statement.execute(
"CREATE TABLE linkis_ps_job_history_group_history "
+ "(id BIGINT, status VARCHAR(50), created_time TIMESTAMP)");
// Inserted in descending id order so that a missing ORDER BY shows up.
statement.execute(
"INSERT INTO linkis_ps_job_history_group_history VALUES "
+ "(7, 'Running', '2026-01-02 01:00:00'), "
+ "(6, 'Running', '2026-01-01 13:00:00'), "
+ "(5, 'Inited', '2026-01-01 12:00:00'), "
+ "(4, 'Scheduled', '2026-01-01 11:00:00'), "
+ "(3, 'Succeed', '2026-01-01 10:00:00'), "
+ "(2, 'Running', '2026-01-01 09:00:00'), "
+ "(1, 'Running', '2025-12-31 23:00:00')");
}
return session;
}
}