Skip to content
Snippets Groups Projects
Commit 7b985304 authored by Arnaud Jelmoni's avatar Arnaud Jelmoni
Browse files

TU

parent b036330c
No related merge requests found
......@@ -436,7 +436,8 @@ public class InfSupGetters extends DataExtractor {
query.append(dbUtils.toDbTimeFieldString(ConfigConst.time)).append(", ")
.append(ConfigConst.read_value).append(", ").append(ConfigConst.write_value);
}
query.append(dbUtils.getTableName(attributeName)).append(" WHERE (").append(selectField).append(" > ")
query.append(" FROM ").append(connector.getSchema()).append(".").append(dbUtils.getTableName(attributeName))
.append(" WHERE (").append(selectField).append(" > ")
.append(lowerValue).append(" AND ").append(selectField).append(" < ").append(upperValue)
.append(") ORDER BY time");
return methods.getAttScalarDataForQuery(query.toString(), dbData);
......@@ -493,7 +494,7 @@ public class InfSupGetters extends DataExtractor {
final String getAttributeDataQuery = new StringBuilder("SELECT ").append(selectFields).append(" FROM ")
.append(connector.getSchema()).append(".").append(dbUtils.getTableName(attributeName))
.append(" WHERE (").append(selectField1).append(" > ").append(lowerValue).append(") ORDER BY time")
.append(" WHERE (").append(selectField1).append(" > ").append(lowerValue).append(")")
.toString();
result = methods.getDataCountFromQuery(getAttributeDataQuery);
}
......@@ -519,7 +520,7 @@ public class InfSupGetters extends DataExtractor {
final String getAttributeDataQuery = new StringBuilder("SELECT COUNT(*) FROM ")
.append(connector.getSchema()).append(".").append(dbUtils.getTableName(attributeName))
.append(" WHERE (").append(selectField).append(" < ").append(lowerValue).append(" OR ")
.append(selectField).append(" > ").append(upperValue).append(") ORDER BY time").toString();
.append(selectField).append(" > ").append(upperValue).append(")").toString();
result = methods.getDataCountFromQuery(getAttributeDataQuery);
}
return result;
......
package fr.soleil.archiving.hdbtdb.api.management.attributes.extractor.datagetters;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import fr.esrf.TangoDs.TimedAttrData;
import fr.soleil.archiving.common.api.exception.ArchivingException;
import fr.soleil.archiving.common.api.tools.DbData;
import fr.soleil.archiving.hdbtdb.api.management.attributes.adtapt.OracleConnectorTest;
public class InfSupGettersTest extends OracleConnectorTest {
@Test
public void getAttDataInfThanTest() throws ArchivingException {
InfSupGetters datagetter = new InfSupGetters(hdbConnector);
DbData result = datagetter.getAttDataInfThan(new String[] { DEFAULT + "double_scalar_rw", "0" });
TimedAttrData[] timedData = result.getDataAsTimedAttrData();
assertEquals(1, timedData.length);
assertEquals(-255.84408754008876, timedData[0].db_ptr[0], 0);
}
@Test
public void getAttDataInfThanCountTest() throws ArchivingException {
InfSupGetters datagetter = new InfSupGetters(hdbConnector);
int result = datagetter.getAttDataInfThanCount(
new String[] { DEFAULT + "double_scalar_rw", "0" });
assertEquals(1, result);
}
@Test
public void getAttDataSupThanTest() throws ArchivingException {
InfSupGetters datagetter = new InfSupGetters(hdbConnector);
DbData result = datagetter.getAttDataSupThan(
new String[] { DEFAULT + "double_scalar_rw", "0" });
TimedAttrData[] timedData = result.getDataAsTimedAttrData();
assertEquals(2, timedData.length);
assertEquals(235.908766, timedData[0].db_ptr[0], 0);
}
@Test
public void getAttDataSupThanCount() throws ArchivingException {
InfSupGetters datagetter = new InfSupGetters(hdbConnector);
int result = datagetter.getAttDataSupThanCount(
new String[] { DEFAULT + "double_scalar_rw", "0" });
assertEquals(2, result);
}
@Test
public void getAttDataInfOrSupThanTest() throws ArchivingException {
InfSupGetters datagetter = new InfSupGetters(hdbConnector);
DbData result = datagetter.getAttDataInfOrSupThan(
new String[] { DEFAULT + "double_scalar_rw", "0", "202" });
TimedAttrData[] timedData = result.getDataAsTimedAttrData();
assertEquals(2, timedData.length);
assertEquals(-255.84408754008876, timedData[0].db_ptr[0], 0);
}
@Test
public void getAttDataInfOrSupThanCount() throws ArchivingException {
InfSupGetters datagetter = new InfSupGetters(hdbConnector);
int result = datagetter.getAttDataInfOrSupThanCount(
new String[] { DEFAULT + "double_scalar_rw", "0", "202" });
assertEquals(2, result);
}
@Test
public void getAttDataSupAndInfThanTest() throws ArchivingException {
InfSupGetters datagetter = new InfSupGetters(hdbConnector);
DbData result = datagetter.getAttDataSupAndInfThan(
new String[] { DEFAULT + "double_scalar_rw", "0", "202" });
TimedAttrData[] timedData = result.getDataAsTimedAttrData();
assertEquals(1, timedData.length);
assertEquals(201.73063210110848, timedData[0].db_ptr[0], 0);
}
@Test
public void getAttDataSupAndInfThanCount() throws ArchivingException {
InfSupGetters datagetter = new InfSupGetters(hdbConnector);
int result = datagetter.getAttDataSupAndInfThanCount(
new String[] { DEFAULT + "double_scalar_rw", "0", "202" });
assertEquals(1, result);
}
}
package fr.soleil.archiving.hdbtdb.api.utils.database;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Arrays;
import org.junit.Test;
import fr.esrf.Tango.AttrWriteType;
import fr.esrf.TangoDs.TangoConst;
import fr.soleil.archiving.common.api.exception.ArchivingException;
import fr.soleil.archiving.hdbtdb.api.management.attributes.adtapt.OracleConnectorTest;
import fr.soleil.archiving.hdbtdb.api.utils.database.IDbUtils.NullableData;
import fr.soleil.lib.project.math.MathConst;
public class DbUtilsTest {
public class DbUtilsTest extends OracleConnectorTest {
@Test
public void getSCalarValueTest() {
DbUtils dbUtils = new OracleDbUtils(null);
DbUtils dbUtils = new OracleDbUtils(hdbConnector);
NullableData<boolean[]> result = dbUtils.getScalarValue("3", "5", TangoConst.Tango_DEV_DOUBLE,
AttrWriteType._READ_WRITE);
assertTrue(Arrays.equals(new double[] { 3, 5 }, (double[]) result.getValue()));
......@@ -126,4 +134,37 @@ public class DbUtilsTest {
assertArrayEquals(new String[] { "[", "SomeString", null, "SomeString", null }, (String[]) result.getValue());
assertArrayEquals(new boolean[] { false, false, true, false, true }, result.getNullElements());
}
@Test
public void getTimeOfLastInsertTest() throws ArchivingException {
DbUtils dbUtils = new OracleDbUtils(hdbConnector);
Timestamp time = dbUtils.getTimeOfLastInsert(DEFAULT + "double_scalar_rw", false);
assertEquals(1355236686000l, time.getTime());
time = dbUtils.getTimeOfLastInsert(DEFAULT + "double_scalar_rw", true);
assertEquals(1355236687000l, time.getTime());
try {
time = dbUtils.getTimeOfLastInsert(DEFAULT + "double_scalar_4", true);
assertFalse("Should not reach", true);
} catch (ArchivingException e) {
assertEquals("Id not found", e.getMessage());
}
}
@Test
public void deleteOldRecordsTest() throws ArchivingException, SQLException {
DbUtils dbUtils = new OracleDbUtils(hdbConnector);
Timestamp time = dbUtils.getTimeOfLastInsert(DEFAULT + "double_scalar_rw", false);
assertEquals(1355236686000l, time.getTime());
dbUtils.deleteOldRecords(0, new String[] { DEFAULT + "double_scalar_rw" });
time = dbUtils.getTimeOfLastInsert(DEFAULT + "double_scalar_rw", false);
assertNull(time);
}
@Test
public void nowTest() throws ArchivingException, SQLException {
DbUtils dbUtils = new OracleDbUtils(hdbConnector);
Timestamp time = dbUtils.now();
assertNotNull(time);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment