Skip to content

Commit

Permalink
Clean up warnings
Browse files Browse the repository at this point in the history
Finally updating the Mongo API cleared a number of warnings; this commit
clears up the rest.
  • Loading branch information
MrCreosote committed Oct 28, 2021
1 parent 1fe59e4 commit a9e58bc
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 57 deletions.
8 changes: 4 additions & 4 deletions src/us/kbase/typedobj/test/BasicValidationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ public static Collection<Object[]> assembleTestInstanceList() throws Exception {
prepareDb();
Object [][] instanceInfo = new Object[validInstanceResources.size()+invalidInstanceResources.size()][2];
for(int k=0; k<validInstanceResources.size(); k++) {
instanceInfo[k][0] = new Integer(k);
instanceInfo[k][1] = new Boolean(true);
instanceInfo[k][0] = k;
instanceInfo[k][1] = true;
}
for(int k=0; k<invalidInstanceResources.size(); k++) {
instanceInfo[k+validInstanceResources.size()][0] = new Integer(k);
instanceInfo[k+validInstanceResources.size()][1] = new Boolean(false);
instanceInfo[k+validInstanceResources.size()][0] = k;
instanceInfo[k+validInstanceResources.size()][1] = false;
}

return Arrays.asList(instanceInfo);
Expand Down
2 changes: 1 addition & 1 deletion src/us/kbase/typedobj/test/DetailedValidationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public static Collection<Object[]> assembleTestInstanceList() throws Exception {
prepareDb();
Object [][] instanceInfo = new Object[resources.size()][1];
for(int k=0; k<resources.size(); k++) {
instanceInfo[k][0] = new Integer(k);
instanceInfo[k][0] = k;
}

return Arrays.asList(instanceInfo);
Expand Down
2 changes: 1 addition & 1 deletion src/us/kbase/typedobj/test/ObjectExtractionByPathTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static Collection<Object[]> assembleTestInstanceList() throws Exception {
if(VERBOSE) System.out.println(" " + instanceResources.size() + " found");
Object [][] instanceInfo = new Object[instanceResources.size()][1];
for(int k=0; k<instanceResources.size(); k++) {
instanceInfo[k][0] = new Integer(k);
instanceInfo[k][0] = k;
}
return Arrays.asList(instanceInfo);
}
Expand Down
25 changes: 0 additions & 25 deletions src/us/kbase/workspace/kbase/AppEventListener.java

This file was deleted.

6 changes: 4 additions & 2 deletions src/us/kbase/workspace/kbase/InitWorkspaceServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
Expand Down Expand Up @@ -395,8 +396,9 @@ private static WorkspaceEventListenerFactory loadFac(final String className)
final Class<WorkspaceEventListenerFactory> inter =
(Class<WorkspaceEventListenerFactory>) cls;
try {
return inter.newInstance();
} catch (IllegalAccessException | InstantiationException e) {
return inter.getDeclaredConstructor().newInstance();
} catch (IllegalAccessException | InstantiationException | IllegalArgumentException |
InvocationTargetException | NoSuchMethodException | SecurityException e) {
throw new WorkspaceInitException(String.format(
"Module %s could not be instantiated: %s", className, e.getMessage()), e);
}
Expand Down
34 changes: 19 additions & 15 deletions src/us/kbase/workspace/test/controllers/shock/ShockController.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@
import org.apache.commons.io.IOUtils;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import org.bson.Document;

import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBObject;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientOptions;
import com.mongodb.MongoCredential;
import com.mongodb.ServerAddress;
import com.mongodb.client.MongoDatabase;

/** Q&D Utility to run a Shock server for the purposes of testing from
* Java.
Expand Down Expand Up @@ -101,7 +100,7 @@ public ShockController(
generateConfig(SHOCK_CONFIG, context, shockcfg);

final MongoClient mc = buildMongo(mongohost, shockMongoDBname, mongouser, mongopwd);
final DB shockDB = mc.getDB(shockMongoDBname);
final MongoDatabase shockDB = mc.getDatabase(shockMongoDBname);

setupWorkarounds(shockDB, adminUser, knownVersion);

Expand Down Expand Up @@ -129,8 +128,10 @@ private MongoClient buildMongo(
}
}

private void setupWorkarounds(DB shockDB, String adminUser,
String version) {
private void setupWorkarounds(
final MongoDatabase shockDB,
final String adminUser,
final String version) {
if ("0.8.23".equals(version)) {
// the version of 0.8.23 above actually works fine without this,
// but it's a few commits beyond the actual 0.8.23 tag, so if the
Expand All @@ -147,25 +148,28 @@ private void setupWorkarounds(DB shockDB, String adminUser,
}
}

private void addAdminUser(DB shockDB, String adminUser) {
final DBObject a = new BasicDBObject("username", adminUser);
private void addAdminUser(final MongoDatabase shockDB, final String adminUser) {
final Document a = new Document("username", adminUser);
a.put("uuid", "095abbb0-07cc-43b3-8fd9-98edfb2541be");
a.put("fullname", "");
a.put("email", "");
a.put("password", "");
a.put("shock_admin", true);
shockDB.getCollection("Users").save(a);
shockDB.getCollection("Users").insertOne(a);
}

private void setCollectionVersions(DB shockDB, int nodever,
int aclver, int authver) {
final DBObject n = new BasicDBObject("name", "Node");
private void setCollectionVersions(
final MongoDatabase shockDB,
int nodever,
int aclver,
int authver) {
final Document n = new Document("name", "Node");
n.put("version", nodever);
final DBObject acl = new BasicDBObject("name", "ACL");
final Document acl = new Document("name", "ACL");
acl.put("version", aclver);
final DBObject auth = new BasicDBObject("name", "Auth");
final Document auth = new Document("name", "Auth");
auth.put("version", authver);
shockDB.getCollection("Versions").insert(Arrays.asList(n, acl, auth));
shockDB.getCollection("Versions").insertMany(Arrays.asList(n, acl, auth));
}

/** Returns the Shock version supplied in the constructor *if* the version
Expand Down
2 changes: 1 addition & 1 deletion test/debugging/jsonclientcaller/JsonClientCaller.java
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public <ARG, RET> RET jsonrpcCall(String method, ARG arg,
if (retError != null) {
String data = retError.get("data") == null ? retError.get("error") : retError.get("data");
throw new ServerException(retError.get("message"),
new Integer(retError.get("code")), retError.get("name"),
Integer.valueOf(retError.get("code")), retError.get("name"),
data);
}
if (res == null && ret)
Expand Down
7 changes: 3 additions & 4 deletions test/performance/ConfigurationsAndThreads.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ public static void timeReadWrite(int writes, String user, String pwd, String sho
// us.kbase.workspace.test.WorkspaceTestCommonDeprecated.destroyAndSetupDB(
// 1, WorkspaceTestCommon.SHOCK, user, null);
//NOTE this setup is just to make it compile, not tested yet
@SuppressWarnings("resource")
final MongoClient mc = new MongoClient(MONGO_HOST);
MC = mc;
final TypeDefinitionDB typeDefDB = new TypeDefinitionDB(
Expand Down Expand Up @@ -238,16 +237,16 @@ private static Perf measurePerformance(int writes, int threads,
for (int i = 0; i < threads; i++) {
if (i + 1 == threads) {
int threadSize = writes - pos;
rwthreads[i] = clazz.newInstance();
rwthreads[i] = clazz.getDeclaredConstructor().newInstance();
rwthreads[i].initialize(threadSize, i + 1);
threadDist.add(threadSize);
} else if (hasMod && i % 2 == 1) {
rwthreads[i] = clazz.newInstance();
rwthreads[i] = clazz.getDeclaredConstructor().newInstance();
rwthreads[i].initialize(minWrites + 1, i + 1);
pos += minWrites + 1;
threadDist.add(minWrites + 1);
} else {
rwthreads[i] = clazz.newInstance();
rwthreads[i] = clazz.getDeclaredConstructor().newInstance();
rwthreads[i].initialize(minWrites, i + 1);
pos += minWrites;
threadDist.add(minWrites);
Expand Down
2 changes: 1 addition & 1 deletion test/performance/PerformanceMeasurement.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static double stddev(final double mean, final List<Long> values,
final double pop = population ? 0 : -1;
double accum = 0;
for (Long d: values) {
accum += Math.pow(new Double(d) - mean, 2);
accum += Math.pow(Double.valueOf(d) - mean, 2);
}
return Math.sqrt(accum / (values.size() + pop));
}
Expand Down
3 changes: 0 additions & 3 deletions war/web.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
<listener>
<listener-class>us.kbase.workspace.kbase.AppEventListener</listener-class>
</listener>
<servlet>
<servlet-name>RootServlet</servlet-name>
<servlet-class>us.kbase.workspace.WorkspaceServer</servlet-class>
Expand Down

0 comments on commit a9e58bc

Please sign in to comment.