Skip to content

Commit

Permalink
fix: disable bulk import for in-memory db
Browse files Browse the repository at this point in the history
  • Loading branch information
anku255 committed Apr 29, 2024
1 parent fcdfb54 commit ddfaa1c
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ protected void doTaskPerApp(AppIdentifier app)
throws TenantOrAppNotFoundException, StorageQueryException, InvalidConfigException, IOException,
DbInitException {

if (StorageLayer.getBaseStorage(main).getType() != STORAGE_TYPE.SQL) {
if (StorageLayer.getBaseStorage(main).getType() != STORAGE_TYPE.SQL || StorageLayer.isInMemDb(main)) {
return;
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/io/supertokens/inmemorydb/Start.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ public void constructor(String processId, boolean silent, boolean isTesting) {

@Override
public Storage createBulkImportProxyStorageInstance() {
// throw not implemented error
throw new UnsupportedOperationException("Unimplemented method 'createBulkImportProxyStorageInstance'");
throw new UnsupportedOperationException("'createBulkImportProxyStorageInstance' is not supported for in-memory db");

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import io.supertokens.pluginInterface.exceptions.StorageQueryException;
import io.supertokens.pluginInterface.multitenancy.AppIdentifier;
import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException;
import io.supertokens.storageLayer.StorageLayer;
import io.supertokens.utils.Utils;
import io.supertokens.webserver.InputParser;
import io.supertokens.webserver.WebserverAPI;
Expand All @@ -58,6 +59,11 @@ public String getPath() {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// API is app specific

if (StorageLayer.isInMemDb(main)) {
throw new ServletException(new BadRequestException("This API is not supported in the in-memory database."));
}

String statusString = InputParser.getQueryParamOrThrowError(req, "status", true);
String paginationToken = InputParser.getQueryParamOrThrowError(req, "paginationToken", true);
Integer limit = InputParser.getIntQueryParamOrThrowError(req, "limit", true);
Expand Down Expand Up @@ -118,6 +124,11 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// API is app specific

if (StorageLayer.isInMemDb(main)) {
throw new ServletException(new BadRequestException("This API is not supported in the in-memory database."));
}

JsonObject input = InputParser.parseJsonObjectOrThrowError(req);
JsonArray users = InputParser.parseArrayOrThrowError(input, "users", false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import io.supertokens.pluginInterface.exceptions.StorageQueryException;
import io.supertokens.pluginInterface.multitenancy.AppIdentifier;
import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException;
import io.supertokens.storageLayer.StorageLayer;
import io.supertokens.webserver.InputParser;
import io.supertokens.webserver.WebserverAPI;
import jakarta.servlet.ServletException;
Expand All @@ -49,6 +50,11 @@ public String getPath() {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// API is app specific

if (StorageLayer.isInMemDb(main)) {
throw new ServletException(new BadRequestException("This API is not supported in the in-memory database."));
}

JsonObject input = InputParser.parseJsonObjectOrThrowError(req);
JsonArray arr = InputParser.parseArrayOrThrowError(input, "ids", false);

Expand Down
13 changes: 9 additions & 4 deletions src/test/java/io/supertokens/test/bulkimport/BulkImportTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.junit.Test;
import org.junit.rules.TestRule;

import io.supertokens.Main;
import io.supertokens.ProcessState;
import io.supertokens.bulkimport.BulkImport;
import io.supertokens.bulkimport.BulkImportUserPaginationContainer;
Expand Down Expand Up @@ -66,8 +67,9 @@ public void shouldAddUsersInBulkImportUsersTable() throws Exception {

TestingProcessManager.TestingProcess process = TestingProcessManager.start(args);
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED));
Main main = process.getProcess();

if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) {
if (StorageLayer.getStorage(main).getType() != STORAGE_TYPE.SQL || StorageLayer.isInMemDb(main)) {
return;
}

Expand Down Expand Up @@ -100,8 +102,9 @@ public void shouldCreatedNewIdsIfDuplicateIdIsFound() throws Exception {

TestingProcessManager.TestingProcess process = TestingProcessManager.start(args);
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED));
Main main = process.getProcess();

if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) {
if (StorageLayer.getStorage(main).getType() != STORAGE_TYPE.SQL || StorageLayer.isInMemDb(main)) {
return;
}

Expand Down Expand Up @@ -140,8 +143,9 @@ public void testGetUsersStatusFilter() throws Exception {

TestingProcessManager.TestingProcess process = TestingProcessManager.start(args);
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED));
Main main = process.getProcess();

if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) {
if (StorageLayer.getStorage(main).getType() != STORAGE_TYPE.SQL || StorageLayer.isInMemDb(main)) {
return;
}

Expand Down Expand Up @@ -209,8 +213,9 @@ public void randomPaginationTest() throws Exception {
process.startProcess();

assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED));
Main main = process.getProcess();

if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) {
if (StorageLayer.getStorage(main).getType() != STORAGE_TYPE.SQL || StorageLayer.isInMemDb(main)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ public void shouldProcessBulkImportUsersInTheSameTenant() throws Exception {
TestingProcess process = startCronProcess();
Main main = process.getProcess();

if (StorageLayer.getBaseStorage(main).getType() != STORAGE_TYPE.SQL || StorageLayer.isInMemDb(main)) {
return;
}

// Create user roles before inserting bulk users
{
UserRoles.createNewRoleOrModifyItsPermissions(main, "role1", null);
Expand Down Expand Up @@ -137,6 +141,10 @@ public void shouldProcessBulkImportUsersInMultipleTenantsWithDifferentStorages()
TestingProcess process = startCronProcess();
Main main = process.getProcess();

if (StorageLayer.getBaseStorage(main).getType() != STORAGE_TYPE.SQL || StorageLayer.isInMemDb(main)) {
return;
}

// Create user roles before inserting bulk users
{
UserRoles.createNewRoleOrModifyItsPermissions(main, "role1", null);
Expand Down Expand Up @@ -197,6 +205,10 @@ public void shouldDeleteEverythingFromtheDBIfAnythingFails() throws Exception {
TestingProcess process = startCronProcess();
Main main = process.getProcess();

if (StorageLayer.getBaseStorage(main).getType() != STORAGE_TYPE.SQL || StorageLayer.isInMemDb(main)) {
return;
}

createTenants(main);

BulkImportSQLStorage storage = (BulkImportSQLStorage) StorageLayer.getStorage(main);
Expand Down Expand Up @@ -225,6 +237,10 @@ public void shouldThrowTenantDoesNotExistError() throws Exception {
TestingProcess process = startCronProcess();
Main main = process.getProcess();

if (StorageLayer.getBaseStorage(main).getType() != STORAGE_TYPE.SQL || StorageLayer.isInMemDb(main)) {
return;
}

BulkImportSQLStorage storage = (BulkImportSQLStorage) StorageLayer.getStorage(main);
AppIdentifier appIdentifier = new AppIdentifier(null, null);

Expand Down Expand Up @@ -254,6 +270,10 @@ public void shouldThrowTenantHaveDifferentStoragesError() throws Exception {
TestingProcess process = startCronProcess();
Main main = process.getProcess();

if (StorageLayer.getBaseStorage(main).getType() != STORAGE_TYPE.SQL || StorageLayer.isInMemDb(main)) {
return;
}

BulkImportSQLStorage storage = (BulkImportSQLStorage) StorageLayer.getStorage(main);
AppIdentifier appIdentifier = new AppIdentifier(null, null);

Expand Down
Loading

0 comments on commit ddfaa1c

Please sign in to comment.