Skip to content

Commit

Permalink
fix the bug with TLE updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dernasherbrezon committed Aug 4, 2024
1 parent 92cc55c commit ca9d8ab
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
23 changes: 15 additions & 8 deletions src/main/java/ru/r2cloud/tle/Housekeeping.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,23 @@ private void reloadTle() {
// store only supported satellites
Map<String, Tle> updated = new HashMap<>();
for (Satellite cur : dao.findAll()) {
Tle curTle;
if (cur.getTle() != null) {
curTle = cur.getTle();
} else {
curTle = tleDao.find(cur.getId(), cur.getName());
Tle oldTle = cur.getTle();
Tle newTle = tleDao.find(cur.getId(), cur.getName());
if (oldTle == null && newTle == null) {
continue;
}
if (oldTle == null && newTle != null) {
cur.setTle(newTle);
}
if (oldTle != null && newTle == null) {
cur.setTle(oldTle);
}
cur.setTle(curTle);
if (curTle != null) {
updated.put(cur.getId(), cur.getTle());
if (oldTle != null && newTle != null) {
// always update to new one
// even if it is the same
cur.setTle(newTle);
}
updated.put(cur.getId(), cur.getTle());
}
if (reloadTle) {
tleDao.saveTle(updated);
Expand Down
29 changes: 27 additions & 2 deletions src/test/java/ru/r2cloud/tle/HousekeepingTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ru.r2cloud.tle;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -97,6 +98,30 @@ public void testReloadFailure() {
assertNotNull(sat.getTle());
}

@Test
public void testTleUpdate() throws Exception {
Housekeeping reloader = new Housekeeping(config, satelliteDao, threadPool, celestrak, tleDao, null, leosatdata, null, priorityService);
reloader.run();
Satellite meteor = satelliteDao.findById("40069");
assertNotNull(meteor);
assertNotNull(meteor.getTle());
assertEquals(meteor.getTle().getRaw()[1], "1 40069U 14037A 18286.52491495 -.00000023 00000-0 92613-5 0 9990");
assertEquals(meteor.getTle().getRaw()[2], "2 40069 98.5901 334.4030 0004544 256.4188 103.6490 14.20654800221188");

config.setProperty("housekeeping.tle.periodMillis", "-10000");

Tle newTle = new Tle(new String[] { "METEOR M-2", "1 40069U 14037A 24217.61569736 .00000303 00000-0 15898-3 0 9993", "2 40069 98.4390 209.6955 0005046 206.9570 153.1346 14.21009510522504" });
tleData.put("40069", newTle);

reloader.run();

meteor = satelliteDao.findById("40069");
assertNotNull(meteor);
assertNotNull(meteor.getTle());
assertEquals(meteor.getTle().getRaw()[1], newTle.getRaw()[1]);
assertEquals(meteor.getTle().getRaw()[2], newTle.getRaw()[2]);
}

@Test
public void testSuccess() throws Exception {
Housekeeping reloader = new Housekeeping(config, satelliteDao, threadPool, celestrak, tleDao, null, leosatdata, null, priorityService);
Expand Down Expand Up @@ -133,15 +158,15 @@ public void start() throws Exception {
config.setProperty("tle.cacheFileLocation", new File(tempFolder.getRoot(), "tle.json").getAbsolutePath());
config.setProperty("satellites.leosatdata.location", new File(tempFolder.getRoot(), "leosatdata.json").getAbsolutePath());
config.setProperty("satellites.leosatdata.new.location", new File(tempFolder.getRoot(), "leosatdata.new.json").getAbsolutePath());
config.setProperty("satellites.satnogs.location", new File(tempFolder.getRoot(), "satnogs.json").getAbsolutePath());
config.setProperty("satellites.satnogs.location", new File(tempFolder.getRoot(), "satnogs.json").getAbsolutePath());
config.update();

satelliteDao = new SatelliteDao(config);

celestrak = mock(CelestrakClient.class);
when(celestrak.downloadTle()).thenReturn(tleData);
tleDao = new TleDao(config);

priorityService = new PriorityService(config, new DefaultClock());

threadPool = mock(ThreadPoolFactory.class);
Expand Down

0 comments on commit ca9d8ab

Please sign in to comment.