0
我是Realm的新手。我在域服务器上对不同用户进行身份验证时遇到了问题。 我写了几行代码来测试后续登录到服务器和域的分离。在领域服务器上进行身份验证的麻烦 - 如果用于打开同一个文件,配置不能不同 -
- 我登录与第一用户[email protected]
- 我填充RealmObject(UserApp),我将它保存到服务器
- 我退出与[email protected]
- 我登录与第二用户[email protected]
- 我检查UserApp不填充该用户(域分离)
- 我退出与[email protected]
- 然后我再次尝试登录与...一起第一个用户[email protected]但我得到以下错误信息:
。
*java.lang.IllegalArgumentException: Configurations cannot be different if used to open the same file.
Cached configuration:
realmDirectory: /data/user/0/com.my.assistant/files/realm-object-server/621c2e6db5e0cf421741f6e9a428c3dc/621c2e6db5e0cf421741f6e9a428c3dc
realmFileName : default
canonicalPath: /data/data/com.my.assistant/files/realm-object-server/621c2e6db5e0cf421741f6e9a428c3dc/621c2e6db5e0cf421741f6e9a428c3dc/default
key: [length: 0]
schemaVersion: 0
migration: null
deleteRealmIfMigrationNeeded: false
durability: FULL
schemaMediator: [email protected]
readOnly: false
compactOnLaunch: null
serverUrl: realm://localhost:9080/621c2e6db5e0cf421741f6e9a428c3dc/default
user: {UserId: 621c2e6db5e0cf421741f6e9a428c3dc, AuthUrl: http://localhost:9080/auth, IsValid: false, Sessions: 0}
errorHandler: [email protected]
deleteRealmOnLogout: false
waitForInitialRemoteData: false
New configuration:
realmDirectory: /data/user/0/com.my.assistant/files/realm-object-server/621c2e6db5e0cf421741f6e9a428c3dc/621c2e6db5e0cf421741f6e9a428c3dc
realmFileName : default
canonicalPath: /data/data/com.my.assistant/files/realm-object-server/621c2e6db5e0cf421741f6e9a428c3dc/621c2e6db5e0cf421741f6e9a428c3dc/default
key: [length: 0]
schemaVersion: 0
migration: null
deleteRealmIfMigrationNeeded: false
durability: FULL
schemaMediator: [email protected]
readOnly: false
compactOnLaunch: null
serverUrl: realm://localhost:9080/621c2e6db5e0cf421741f6e9a428c3dc/default
user: {UserId: 621c2e6db5e0cf421741f6e9a428c3dc, AuthUrl: http://localhost:9080/auth, IsValid: true, Sessions: 0}
errorHandler: [email protected]
deleteRealmOnLogout: false
waitForInitialRemoteData: false
at io.realm.RealmCache.validateConfiguration(RealmCache.java:461)
at io.realm.RealmCache.doCreateRealmOrGetFromCache(RealmCache.java:337)
at io.realm.RealmCache.createRealmOrGetFromCache(RealmCache.java:284)
at io.realm.Realm.getInstance(Realm.java:301)
at com.my.assistant.LoginInstrTest2.setConfigurationSyncUser(LoginInstrTest2.java:149)
at com.my.assistant.LoginInstrTest2.loginUser(LoginInstrTest2.java:129)
at com.my.assistant.LoginInstrTest2.veryfyRealmUserInstance(LoginInstrTest2.java:98)
at java.lang.reflect.Method.invoke(Native Method)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:59)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:262)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2074)*
有人可以告诉我为什么吗?我的这个代码的意图是测试一个使用领域的Android应用程序的初始登录/注销。用户应该使用不同的凭证登录和退出应用程序。这听起来像是应该有一种方法来为该用户获得之前创建的SyncConfiguration,而不是创建一个新的SyncConfiguration ...但是,如果是这种情况,我不知道该怎么做......。
这是我的代码:
// -----------主要代码:
SyncUser userLogged;
//Login with first user. This time the login completes successfully
userLogged = loginUser("[email protected]", "pluto");
insertUserAppSyncRealm();
RealmResults<UserApp> res = realm.where(UserApp.class)
.beginsWith("username", "situs")
.findAll();
System.out.println(" @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Size table pippo " + res.size());
UserApp resUser = res.last();
System.out.println(" @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ID " + resUser.getId());
userLogged.logout();
//Login with second user OK
userLogged = loginUser("[email protected]", "paperino");
RealmResults<UserApp> res2 = realm.where(UserApp.class)
.beginsWith("username", "situs")
.findAll(); //arrivato qui da "Configurations cannot be different if used to open the same file"
System.out.println(" @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Size table usertest " + res2.size());
userLogged.logout();
//Login again with first user. This time the login fails ("Configurations cannot be different if used to open the same file")
userLogged = loginUser("[email protected]", "pluto");
RealmResults<UserApp> res3 = realm.where(UserApp.class)
.beginsWith("username", "situs")
.findAll();
System.out.println(" @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Size table pippo " + res3.size());
userLogged.logout();
// -----------使用功能:
public SyncUser loginUser(String username, String password) {
SyncUser userLogged;
SyncCredentials myCredentials = SyncCredentials.usernamePassword(username, password, false);
userLogged = SyncUser.login(myCredentials, authURL);
setConfigurationSyncUser(userLogged);
return userLogged;
}
public void setConfigurationSyncUser(SyncUser user) {
String user1RealmUrl = "realm://localhost:9080/~/default";
SyncConfiguration config = new SyncConfiguration.Builder(user, user1RealmUrl).
errorHandler(new SyncSession.ErrorHandler() {
public void onError(SyncSession session, ObjectServerError error) {
fail("Realm unexpected error: " + error);
}
})
.build();
realm = Realm.getInstance(config); //fails ("Configurations cannot be different if used to open the same file")
}
public void insertUserAppSyncRealm() {
UserApp user = new UserApp();
populateUser(user);
realm.beginTransaction();
realm.insert(user);
realm.commitTransaction();
}
private void populateUser(UserApp user) {
user.setUsername("[email protected]");
user.setPassword("12345678");
user.setId(UUID.randomUUID().toString());
}
预先感谢你样的建议?
这应该工作。问题在于你的错误处理程序在两种配置之间是不同的:'com.my.assistant.LoginInstrTest2 $ 1 @ 397b523' vs'com.my.assistant.LoginInstrTest2 $ 1 @ cdafa20' –
不幸的是它没有工作...... I也尝试完全删除错误处理程序,但我得到相同的错误...任何其他想法? – Selvaggia
你有新的异常堆栈跟踪和日志吗? – EpicPandaForce