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