Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dependencies.list
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Realm Sync Core release used by Realm Java
# https://github.com/realm/realm-sync/releases
REALM_SYNC_VERSION=2.0.2
REALM_SYNC_SHA256=33c9dace6dc280712101110895d38509bbca74fdb31ba31b61dc0ad383472b03
REALM_SYNC_VERSION=2.1.0
REALM_SYNC_SHA256=cd52b2ee53ef80b4b9ec80eede7ca5fa28a96353ad7e4d26cf516dbb12586966

# Object Server Release used by Integration tests. Installed using NPM.
# Use `npm view realm-object-server versions` to get a list of available versions.
Expand Down
1 change: 1 addition & 0 deletions realm/realm-library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ task downloadCore() {

doLast {
if (shouldDownloadCore()) {
println "Downloading: http://static.realm.io/downloads/sync/realm-sync-android-${project.coreVersion}.tar.gz"
download {
src "http://static.realm.io/downloads/sync/realm-sync-android-${project.coreVersion}.tar.gz"
dest project.coreArchiveFile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package io.realm;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Before;
Expand All @@ -37,6 +35,7 @@
import io.realm.rule.RunInLooperThread;
import io.realm.rule.RunTestInLooperThread;
import io.realm.rule.TestRealmConfigurationFactory;
import io.realm.util.RandomGenerator;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand All @@ -55,12 +54,10 @@ public class RealmCacheTests {
public final TestRealmConfigurationFactory configFactory = new TestRealmConfigurationFactory();

private RealmConfiguration defaultConfig;
private Context context;

@Before
public void setUp() {
defaultConfig = configFactory.createConfiguration();
context = InstrumentationRegistry.getInstrumentation().getContext();
}

// Tests that the closed Realm isn't kept in the Realm instance cache.
Expand Down Expand Up @@ -104,10 +101,8 @@ public void dynamicRealmCacheIsCleared() {
@Test
public void getInstanceClearsCacheWhenFailed() {
String REALM_NAME = "invalid_cache.realm";
RealmConfiguration configA = configFactory.createConfiguration(REALM_NAME,
TestHelper.getRandomKey(42));
RealmConfiguration configB = configFactory.createConfiguration(REALM_NAME,
TestHelper.getRandomKey(43));
RealmConfiguration configA = configFactory.createConfiguration(REALM_NAME, RandomGenerator.getRandomKey(42));
RealmConfiguration configB = configFactory.createConfiguration(REALM_NAME, RandomGenerator.getRandomKey(43));

Realm realm = Realm.getInstance(configA); // Creates starting Realm with key 1.
realm.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import io.realm.rx.ObjectChange;
import io.realm.rx.RealmObservableFactory;
import io.realm.rx.RxObservableFactory;
import io.realm.util.RandomGenerator;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand Down Expand Up @@ -329,7 +330,7 @@ public void standardSetup() {
RealmConfiguration config = new RealmConfiguration.Builder(context)
.directory(configFactory.getRoot())
.name("foo.realm")
.encryptionKey(TestHelper.getRandomKey())
.encryptionKey(RandomGenerator.getRandomKey())
.schemaVersion(42)
.migration(new RealmMigration() {
@Override
Expand Down Expand Up @@ -515,11 +516,11 @@ public void schemaVersion_differentVersionsThrows() {
public void encryptionKey_differentEncryptionKeysThrows() {
RealmConfiguration config1 = new RealmConfiguration.Builder(context)
.directory(configFactory.getRoot())
.encryptionKey(TestHelper.getRandomKey())
.encryptionKey(RandomGenerator.getRandomKey())
.build();
RealmConfiguration config2 = new RealmConfiguration.Builder(context)
.directory(configFactory.getRoot())
.encryptionKey(TestHelper.getRandomKey())
.encryptionKey(RandomGenerator.getRandomKey())
.build();

Realm realm1 = Realm.getInstance(config1);
Expand Down Expand Up @@ -601,15 +602,15 @@ public void constructBuilder_differentDirSameName() throws IOException {
@Test
public void encryptionKey_keyStorage() throws Exception {
// Generates a key and uses it in a RealmConfiguration.
byte[] oldKey = TestHelper.getRandomKey(12345);
byte[] oldKey = RandomGenerator.getRandomKey(12345);
byte[] key = oldKey;
RealmConfiguration config = new RealmConfiguration.Builder(context)
.directory(configFactory.getRoot())
.encryptionKey(key)
.build();

// Generates a different key and assigns it to the same variable.
byte[] newKey = TestHelper.getRandomKey(67890);
byte[] newKey = RandomGenerator.getRandomKey(67890);
MoreAsserts.assertNotEqual(key, newKey);
key = newKey;
MoreAsserts.assertEquals(key, newKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import io.realm.entities.Dog;
import io.realm.exceptions.RealmFileException;
import io.realm.rule.TestRealmConfigurationFactory;
import io.realm.util.RandomGenerator;

import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.assertEquals;
Expand Down Expand Up @@ -139,7 +140,7 @@ public void delete() {
// Tests if an in-memory Realm can be written to disk with/without encryption.
@Test
public void writeCopyTo() {
byte[] key = TestHelper.getRandomKey();
byte[] key = RandomGenerator.getRandomKey();
String fileName = IDENTIFIER + ".realm";
String encFileName = IDENTIFIER + ".enc.realm";
RealmConfiguration conf = configFactory.createConfigurationBuilder()
Expand Down Expand Up @@ -173,7 +174,7 @@ public void writeCopyTo() {
try {
RealmConfiguration wrongKeyConf = configFactory.createConfigurationBuilder()
.name(encFileName)
.encryptionKey(TestHelper.getRandomKey(42))
.encryptionKey(RandomGenerator.getRandomKey(42))
.build();
Realm.getInstance(wrongKeyConf);
fail("Realm.getInstance should fail with RealmFileException");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
import io.realm.rule.RunTestInLooperThread;
import io.realm.rule.TestRealmConfigurationFactory;
import io.realm.util.ExceptionHolder;
import io.realm.util.RandomGenerator;
import io.realm.util.RealmThread;

import static io.realm.TestHelper.testNoObjectFound;
Expand Down Expand Up @@ -992,7 +993,7 @@ public void compactRealm_failsIfOpen() {

@Test
public void compactRealm_encryptedEmptyRealm() {
RealmConfiguration realmConfig = configFactory.createConfiguration("enc.realm", TestHelper.getRandomKey());
RealmConfiguration realmConfig = configFactory.createConfiguration("enc.realm", RandomGenerator.getRandomKey());
Realm realm = Realm.getInstance(realmConfig);
realm.close();
assertTrue(Realm.compactRealm(realmConfig));
Expand All @@ -1005,7 +1006,7 @@ public void compactRealm_encryptedEmptyRealm() {
@Test
public void compactRealm_encryptedPopulatedRealm() {
final int DATA_SIZE = 100;
RealmConfiguration realmConfig = configFactory.createConfiguration("enc.realm", TestHelper.getRandomKey());
RealmConfiguration realmConfig = configFactory.createConfiguration("enc.realm", RandomGenerator.getRandomKey());
Realm realm = Realm.getInstance(realmConfig);

populateTestRealm(realm, DATA_SIZE);
Expand Down Expand Up @@ -2085,8 +2086,8 @@ public void copyToRealmOrUpdate_bug4957() {

@Test
public void getInstance_differentEncryptionKeys() {
byte[] key1 = TestHelper.getRandomKey(42);
byte[] key2 = TestHelper.getRandomKey(42);
byte[] key1 = RandomGenerator.getRandomKey(42);
byte[] key2 = RandomGenerator.getRandomKey(42);

// Makes sure the key is the same, but in two different instances.
assertArrayEquals(key1, key2);
Expand Down Expand Up @@ -2125,10 +2126,10 @@ public void writeEncryptedCopyTo() throws Exception {
final String DECRYPTED_REALM_FILE_NAME = "decryptedTestRealm.realm";

RealmConfiguration encryptedRealmConfig = configFactory.createConfiguration(ENCRYPTED_REALM_FILE_NAME,
TestHelper.getRandomKey());
RandomGenerator.getRandomKey());

RealmConfiguration reEncryptedRealmConfig = configFactory.createConfiguration(RE_ENCRYPTED_REALM_FILE_NAME,
TestHelper.getRandomKey());
RandomGenerator.getRandomKey());

RealmConfiguration decryptedRealmConfig = configFactory.createConfiguration(DECRYPTED_REALM_FILE_NAME);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,11 @@
import java.util.Date;
import java.util.Locale;
import java.util.Random;
import java.util.UUID;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

import io.realm.entities.AllTypes;
import io.realm.entities.AllTypesPrimaryKey;
import io.realm.entities.AnnotationIndexTypes;
import io.realm.entities.BacklinksSource;
Expand All @@ -58,13 +56,13 @@
import io.realm.entities.PrimaryKeyAsString;
import io.realm.internal.Collection;
import io.realm.internal.OsObject;
import io.realm.internal.OsObjectStore;
import io.realm.internal.SharedRealm;
import io.realm.internal.Table;
import io.realm.internal.async.RealmThreadPoolExecutor;
import io.realm.log.LogLevel;
import io.realm.log.RealmLogger;
import io.realm.rule.TestRealmConfigurationFactory;
import io.realm.util.RandomGenerator;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.fail;
Expand All @@ -75,7 +73,6 @@ public class TestHelper {
public static final int STANDARD_WAIT_SECS = 100;

private static final Charset UTF_8 = Charset.forName("UTF-8");
private static final Random RANDOM = new Random();

public static class ExpectedCountCallback implements RealmCache.Callback {

Expand Down Expand Up @@ -319,27 +316,6 @@ public static InputStream stringToStream(String str) {
return new ByteArrayInputStream(str.getBytes(UTF_8));
}

// Returns a random key used by encrypted Realms.
public static byte[] getRandomKey() {
byte[] key = new byte[64];
RANDOM.nextBytes(key);
return key;
}

public static String getRandomEmail() {
StringBuilder sb = new StringBuilder(UUID.randomUUID().toString().toLowerCase());
sb.append('@');
sb.append("androidtest.realm.io");
return sb.toString();
}

// Returns a random key from the given seed. Used by encrypted Realms.
public static byte[] getRandomKey(long seed) {
byte[] key = new byte[64];
new Random(seed).nextBytes(key);
return key;
}

/**
* Returns a RealmLogger that will fail if it is asked to log a message above a certain level.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.realm.RealmObject;
import io.realm.annotations.Ignore;
import io.realm.annotations.PrimaryKey;
import io.realm.util.RandomGenerator;

public class DefaultValueConstructor extends RealmObject {

Expand Down Expand Up @@ -86,7 +87,7 @@ public class DefaultValueConstructor extends RealmObject {
public DefaultValueConstructor() {
fieldIgnored = FIELD_IGNORED_DEFAULT_VALUE;
fieldString = FIELD_STRING_DEFAULT_VALUE;
fieldRandomString = lastRandomStringValue = UUID.randomUUID().toString();
fieldRandomString = lastRandomStringValue = RandomGenerator.newRandomUUID();
fieldShort = FIELD_SHORT_DEFAULT_VALUE;
fieldInt = FIELD_INT_DEFAULT_VALUE;
fieldLongPrimaryKey = FIELD_LONG_PRIMARY_KEY_DEFAULT_VALUE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
package io.realm.entities;

import java.util.Date;
import java.util.UUID;

import io.realm.RealmList;
import io.realm.RealmObject;
import io.realm.annotations.Ignore;
import io.realm.annotations.PrimaryKey;
import io.realm.util.RandomGenerator;

public class DefaultValueOfField extends RealmObject {

Expand Down Expand Up @@ -90,7 +90,7 @@ public class DefaultValueOfField extends RealmObject {

@Ignore private String fieldIgnored = FIELD_IGNORED_DEFAULT_VALUE;
private String fieldString = FIELD_STRING_DEFAULT_VALUE;
private String fieldRandomString = lastRandomStringValue = UUID.randomUUID().toString();
private String fieldRandomString = lastRandomStringValue = RandomGenerator.newRandomUUID();
private short fieldShort = FIELD_SHORT_DEFAULT_VALUE;
private int fieldInt = FIELD_INT_DEFAULT_VALUE;
@PrimaryKey private long fieldLongPrimaryKey = FIELD_LONG_PRIMARY_KEY_DEFAULT_VALUE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
package io.realm.entities;

import java.util.Date;
import java.util.UUID;

import io.realm.RealmList;
import io.realm.RealmObject;
import io.realm.annotations.Ignore;
import io.realm.annotations.PrimaryKey;
import io.realm.util.RandomGenerator;

public class DefaultValueSetter extends RealmObject {

Expand Down Expand Up @@ -86,7 +86,7 @@ public class DefaultValueSetter extends RealmObject {
public DefaultValueSetter() {
setFieldIgnored(FIELD_IGNORED_DEFAULT_VALUE);
setFieldString(FIELD_STRING_DEFAULT_VALUE);
setFieldRandomString(lastRandomStringValue = UUID.randomUUID().toString());
setFieldRandomString(lastRandomStringValue = RandomGenerator.newRandomUUID());
setFieldShort(FIELD_SHORT_DEFAULT_VALUE);
setFieldInt(FIELD_INT_DEFAULT_VALUE);
setFieldLongPrimaryKey(FIELD_LONG_PRIMARY_KEY_DEFAULT_VALUE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@

package io.realm.entities;

import java.util.UUID;

import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey;
import io.realm.util.RandomGenerator;

public class RandomPrimaryKey extends RealmObject {

Expand All @@ -30,7 +29,7 @@ public class RandomPrimaryKey extends RealmObject {

public static int FIELD_INT_DEFAULT_VALUE = 1357924;

@PrimaryKey private String fieldRandomPrimaryKey = UUID.randomUUID().toString();
@PrimaryKey private String fieldRandomPrimaryKey = RandomGenerator.newRandomUUID();
private int fieldInt = FIELD_INT_DEFAULT_VALUE;

public RandomPrimaryKey() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand All @@ -41,6 +40,7 @@
import io.realm.RealmConfiguration;
import io.realm.TestHelper;
import io.realm.internal.android.AndroidCapabilities;
import io.realm.util.RandomGenerator;


/**
Expand Down Expand Up @@ -265,7 +265,7 @@ void setBackgroundHandler(Handler backgroundHandler) {
protected void before() throws Throwable {
super.before();

RealmConfiguration config = createConfiguration(UUID.randomUUID().toString());
RealmConfiguration config = createConfiguration(RandomGenerator.newRandomUUID());
LinkedList<Object> refs = new LinkedList<>();
List<Realm> realms = new LinkedList<>();
LinkedList<Closeable> closeables = new LinkedList<>();
Expand Down
Loading