use of org.apache.solr.common.util.SuppressForbidden in project lucene-solr by apache.
the class AbstractSqlEntityProcessorTestCase method modifySomeCountries.
@SuppressForbidden(reason = "Needs currentTimeMillis to set change time for SQL query")
public String[] modifySomeCountries() throws Exception {
underlyingDataModified = true;
int numberToChange = random().nextInt(countries.length + 1);
Set<String> changeSet = new HashSet<>();
Connection conn = null;
PreparedStatement change = null;
// One second in the future ensures a change time after the last import (DIH
// uses second precision only)
Timestamp theTime = new Timestamp(System.currentTimeMillis() + 1000);
log.debug("COUNTRY UPDATE USING TIMESTAMP: " + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.ROOT).format(theTime));
try {
conn = newConnection();
change = conn.prepareStatement("update countries set country_name=?, last_modified=? where code=?");
for (int i = 0; i < numberToChange; i++) {
int tryIndex = random().nextInt(countries.length);
String code = countries[tryIndex][0];
if (!changeSet.contains(code)) {
changeSet.add(code);
change.setString(1, "MODIFIED " + countries[tryIndex][1]);
change.setTimestamp(2, theTime);
change.setString(3, code);
Assert.assertEquals(1, change.executeUpdate());
}
}
} catch (SQLException e) {
throw e;
} finally {
try {
change.close();
} catch (Exception ex) {
}
try {
conn.close();
} catch (Exception ex) {
}
}
return changeSet.toArray(new String[changeSet.size()]);
}
use of org.apache.solr.common.util.SuppressForbidden in project lucene-solr by apache.
the class TestInjection method waitForInSyncWithLeader.
@SuppressForbidden(reason = "Need currentTimeMillis, because COMMIT_TIME_MSEC_KEY use currentTimeMillis as value")
public static boolean waitForInSyncWithLeader(SolrCore core, ZkController zkController, String collection, String shardId) throws InterruptedException {
if (waitForReplicasInSync == null)
return true;
log.info("Start waiting for replica in sync with leader");
long currentTime = System.currentTimeMillis();
Pair<Boolean, Integer> pair = parseValue(waitForReplicasInSync);
boolean enabled = pair.first();
if (!enabled)
return true;
long t = System.currentTimeMillis() - 200;
try {
for (int i = 0; i < pair.second(); i++) {
if (core.isClosed())
return true;
Replica leaderReplica = zkController.getZkStateReader().getLeaderRetry(collection, shardId);
try (HttpSolrClient leaderClient = new HttpSolrClient.Builder(leaderReplica.getCoreUrl()).build()) {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set(CommonParams.QT, ReplicationHandler.PATH);
params.set(COMMAND, CMD_DETAILS);
NamedList<Object> response = leaderClient.request(new QueryRequest(params));
long leaderVersion = (long) ((NamedList) response.get("details")).get("indexVersion");
RefCounted<SolrIndexSearcher> searcher = core.getSearcher();
try {
String localVersion = searcher.get().getIndexReader().getIndexCommit().getUserData().get(SolrIndexWriter.COMMIT_TIME_MSEC_KEY);
if (localVersion == null && leaderVersion == 0 && !core.getUpdateHandler().getUpdateLog().hasUncommittedChanges())
return true;
if (localVersion != null && Long.parseLong(localVersion) == leaderVersion && (leaderVersion >= t || i >= 6)) {
log.info("Waiting time for tlog replica to be in sync with leader: {}", System.currentTimeMillis() - currentTime);
return true;
} else {
log.debug("Tlog replica not in sync with leader yet. Attempt: {}. Local Version={}, leader Version={}", i, localVersion, leaderVersion);
Thread.sleep(500);
}
} finally {
searcher.decref();
}
}
}
} catch (Exception e) {
log.error("Exception when wait for replicas in sync with master");
}
return false;
}
use of org.apache.solr.common.util.SuppressForbidden in project lucene-solr by apache.
the class AbstractSqlEntityProcessorTestCase method populateData.
@SuppressForbidden(reason = "Needs currentTimeMillis to set change time for SQL query")
@Override
protected void populateData(Connection conn) throws Exception {
Statement s = null;
PreparedStatement ps = null;
// 10 seconds ago
Timestamp theTime = new Timestamp(System.currentTimeMillis() - 10000);
try {
s = conn.createStatement();
s.executeUpdate("create table countries(code varchar(3) not null primary key, country_name varchar(50), deleted char(1) default 'N', last_modified timestamp not null)");
s.executeUpdate("create table people(id int not null primary key, name varchar(50), country_code char(2), deleted char(1) default 'N', last_modified timestamp not null)");
s.executeUpdate("create table people_sports(id int not null primary key, person_id int, sport_name varchar(50), deleted char(1) default 'N', last_modified timestamp not null)");
log.debug("INSERTING DB DATA USING TIMESTAMP: " + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.ROOT).format(theTime));
ps = conn.prepareStatement("insert into countries (code, country_name, last_modified) values (?,?,?)");
for (String[] country : countries) {
ps.setString(1, country[0]);
ps.setString(2, country[1]);
ps.setTimestamp(3, theTime);
Assert.assertEquals(1, ps.executeUpdate());
}
ps.close();
ps = conn.prepareStatement("insert into people (id, name, country_code, last_modified) values (?,?,?,?)");
for (Object[] person : people) {
ps.setInt(1, (Integer) person[0]);
ps.setString(2, (String) person[1]);
ps.setString(3, (String) person[2]);
ps.setTimestamp(4, theTime);
Assert.assertEquals(1, ps.executeUpdate());
}
ps.close();
ps = conn.prepareStatement("insert into people_sports (id, person_id, sport_name, last_modified) values (?,?,?,?)");
for (Object[] sport : people_sports) {
ps.setInt(1, (Integer) sport[0]);
ps.setInt(2, (Integer) sport[1]);
ps.setString(3, (String) sport[2]);
ps.setTimestamp(4, theTime);
Assert.assertEquals(1, ps.executeUpdate());
}
ps.close();
conn.commit();
conn.close();
} catch (Exception e) {
throw e;
} finally {
try {
ps.close();
} catch (Exception ex) {
}
try {
s.close();
} catch (Exception ex) {
}
try {
conn.close();
} catch (Exception ex) {
}
}
}
use of org.apache.solr.common.util.SuppressForbidden in project lucene-solr by apache.
the class TestFileListEntityProcessor method testNTOT.
@SuppressForbidden(reason = "Needs currentTimeMillis to set last modified time")
@Test
public void testNTOT() throws IOException {
File tmpdir = createTempDir().toFile();
createFile(tmpdir, "a.xml", "a.xml".getBytes(StandardCharsets.UTF_8), true);
createFile(tmpdir, "b.xml", "b.xml".getBytes(StandardCharsets.UTF_8), true);
createFile(tmpdir, "c.props", "c.props".getBytes(StandardCharsets.UTF_8), true);
Map attrs = createMap(FileListEntityProcessor.FILE_NAME, "xml$", FileListEntityProcessor.BASE_DIR, tmpdir.getAbsolutePath(), FileListEntityProcessor.OLDER_THAN, "'NOW'");
List<String> fList = getFiles(null, attrs);
assertEquals(2, fList.size());
attrs = createMap(FileListEntityProcessor.FILE_NAME, ".xml$", FileListEntityProcessor.BASE_DIR, tmpdir.getAbsolutePath(), FileListEntityProcessor.NEWER_THAN, "'NOW-2HOURS'");
fList = getFiles(null, attrs);
assertEquals(2, fList.size());
// Use a variable for newerThan
attrs = createMap(FileListEntityProcessor.FILE_NAME, ".xml$", FileListEntityProcessor.BASE_DIR, tmpdir.getAbsolutePath(), FileListEntityProcessor.NEWER_THAN, "${a.x}");
VariableResolver resolver = new VariableResolver();
String lastMod = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ROOT).format(new Date(System.currentTimeMillis() - 50000));
resolver.addNamespace("a", createMap("x", lastMod));
createFile(tmpdir, "t.xml", "t.xml".getBytes(StandardCharsets.UTF_8), false);
fList = getFiles(resolver, attrs);
assertEquals(1, fList.size());
assertEquals("File name must be t.xml", new File(tmpdir, "t.xml").getAbsolutePath(), fList.get(0));
}
use of org.apache.solr.common.util.SuppressForbidden in project lucene-solr by apache.
the class IndexFetcher method markReplicationStart.
@SuppressForbidden(reason = "Need currentTimeMillis for debugging/stats")
private void markReplicationStart() {
replicationTimer = new RTimer();
replicationStartTimeStamp = new Date();
}
Aggregations