Skip to content

Commit

Permalink
[cuebot] Fix a few database query and test issues. (#1232)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcipriano committed Jan 21, 2023
1 parent 6339087 commit 5d5ef8f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -262,30 +262,25 @@ public void updateProcMemoryUsage(FrameInterface f, long rss, long maxRss,
"SELECT pk_frame FROM proc WHERE pk_frame=? FOR UPDATE",
String.class, f.getFrameId()).equals(f.getFrameId())) {

getJdbcTemplate().update(UPDATE_PROC_MEMORY_USAGE,
rss, maxRss, vss, maxVss,
usedGpuMemory, maxUsedGpuMemory, f.getFrameId());
}
getJdbcTemplate().update(new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection conn)
throws SQLException {
PreparedStatement updateProc = conn.prepareStatement(
UPDATE_PROC_MEMORY_USAGE);
updateProc.setLong(1, rss);
updateProc.setLong(2, maxRss);
updateProc.setLong(3, vss);
updateProc.setLong(4, maxVss);
updateProc.setLong(5, usedGpuMemory);
updateProc.setLong(6, maxUsedGpuMemory);
updateProc.setBytes(7, children);
updateProc.setString(8, f.getFrameId());
return updateProc;
}
}
);
@Override
public PreparedStatement createPreparedStatement(Connection conn)
throws SQLException {
PreparedStatement updateProc = conn.prepareStatement(
UPDATE_PROC_MEMORY_USAGE);
updateProc.setLong(1, rss);
updateProc.setLong(2, maxRss);
updateProc.setLong(3, vss);
updateProc.setLong(4, maxVss);
updateProc.setLong(5, usedGpuMemory);
updateProc.setLong(6, maxUsedGpuMemory);
updateProc.setBytes(7, children);
updateProc.setString(8, f.getFrameId());
return updateProc;
}
});
}
catch (DataAccessException dae) {
} catch (DataAccessException dae) {
logger.info("The proc for frame " + f +
" could not be updated with new memory stats: " + dae);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ public void testFifoSchedulingDisabled() throws Exception {
List<String> sortedJobs = new ArrayList<String>(jobs);
Collections.sort(sortedJobs,
Comparator.comparing(jobId -> jobManager.getJob(jobId).getName()));
assertNotEquals(jobs, sortedJobs);

for (int i = 0; i < count; i++) {
assertEquals("pipe-default-testuser_job" + i,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package com.imageworks.spcue.test.dao.postgres;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
Expand All @@ -44,7 +45,6 @@
import com.imageworks.spcue.LayerDetail;
import com.imageworks.spcue.LayerInterface;
import com.imageworks.spcue.LimitEntity;
import com.imageworks.spcue.LimitInterface;
import com.imageworks.spcue.ResourceUsage;
import com.imageworks.spcue.config.TestAppConfig;
import com.imageworks.spcue.dao.DepartmentDao;
Expand All @@ -63,9 +63,11 @@
import com.imageworks.spcue.util.FrameSet;
import com.imageworks.spcue.util.JobLogUtil;

import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

@Transactional
Expand Down Expand Up @@ -116,7 +118,11 @@ public void testMode() {
}

public LayerDetail getLayer() {
List<LayerDetail> layers = getLayers();
return layers.get(layers.size()-1);
}

public List<LayerDetail> getLayers() {
JobSpec spec = jobLauncher.parse(new File("src/test/resources/conf/jobspec/jobspec.xml"));
JobDetail job = spec.getJobs().get(0).detail;
job.groupId = ROOT_FOLDER;
Expand All @@ -126,14 +132,13 @@ public LayerDetail getLayer() {
job.facilityId = facilityDao.getDefaultFacility().getId();
jobDao.insertJob(job, jobLogUtil);

LayerDetail lastLayer= null;
List<LayerDetail> result = new ArrayList<>();
String limitId = limitDao.createLimit(LIMIT_NAME, LIMIT_MAX_VALUE);
limitDao.createLimit(LIMIT_TEST_A, 1);
limitDao.createLimit(LIMIT_TEST_B, 2);
limitDao.createLimit(LIMIT_TEST_C, 3);

for (BuildableLayer buildableLayer: spec.getJobs().get(0).getBuildableLayers()) {

LayerDetail layer = buildableLayer.layerDetail;
FrameSet frameSet = new FrameSet(layer.range);
int num_frames = frameSet.size();
Expand All @@ -147,10 +152,10 @@ public LayerDetail getLayer() {
layerDao.insertLayerDetail(layer);
layerDao.insertLayerEnvironment(layer, buildableLayer.env);
layerDao.addLimit(layer, limitId);
lastLayer = layer;
result.add(layer);
}

return lastLayer;
return result;
}

public JobDetail getJob() {
Expand Down Expand Up @@ -202,16 +207,17 @@ public void testGetLayerDetail() {

LayerDetail l2 = layerDao.getLayerDetail(layer);
LayerDetail l3 = layerDao.getLayerDetail(layer.id);
assertEquals(l2, l3);
assertEquals(layer, l2);
assertEquals(layer, l3);
}

@Test
@Transactional
@Rollback(true)
public void testGetLayerDetails() {
LayerDetail layer = getLayer();
List<LayerDetail> ld = layerDao.getLayerDetails(getJob());
assertEquals(ld.get(0).name, LAYER_NAME);
List<LayerDetail> wantLayers = getLayers();
List<LayerDetail> gotLayers = layerDao.getLayerDetails(getJob());
assertThat(gotLayers, containsInAnyOrder(wantLayers.toArray()));
}

@Test
Expand Down

0 comments on commit 5d5ef8f

Please sign in to comment.