public void setUp() { // Reset RNG for each test (it's static so not reset by junit). random = new DummyRandomSource(1234); URI = FreenetURI.generateRandomCHK(random); }
DummyRandomSource random = new DummyRandomSource(); if(i % NUMBER_OF_NODES == 0) Logger.normal(RealNodeRoutingTest.class, String.valueOf(i)); int length = (int)Math.pow(NUMBER_OF_NODES, random.nextDouble()); int nodeA = random.nextInt(NUMBER_OF_NODES); int nodeB = (nodeA+length)%NUMBER_OF_NODES; random.nextBytes(buf); String keyName = HexUtil.bytesToHex(buf);
DummyRandomSource random = new DummyRandomSource(3142); Node[] nodes = new Node[NUMBER_OF_NODES]; Logger.normal(RealNodeProbeTest.class, "Creating nodes..."); waitForPingAverage(0.5, nodes, new DummyRandomSource(3143), MAX_PINGS, 1000); nodeConfig.set(option, Boolean.valueOf(r.readLine())); } else nodes[index].startProbe(htl, random.nextLong(), types[selection], print); } catch (Exception e) {
System.out.println("Busy network test (inserts/retrieves in quantity/stress test)"); System.out.println(); DummyRandomSource random = new DummyRandomSource(); for(int i=0;i<INSERT_KEYS;i++) { System.err.println("Inserting "+i+" of "+INSERT_KEYS); int node1 = random.nextInt(NUMBER_OF_NODES); Node randomNode = nodes[node1]; String dataString = baseString + i;
int block; do { block = random.nextInt(total); } while (hits[block]); hits[block] = true;
public static byte[] randomKey() { byte[] buf = new byte[KEY_LENGTH]; random.nextBytes(buf); return buf; }
public DummyRandomSource(long seed) { setSeed(seed); }
int block; do { block = random.nextInt(total); } while (hits[block]); hits[block] = true;
protected InsertBlock generateBlock(DummyRandomSource random) throws MalformedURLException { byte[] data = new byte[FILE_SIZE]; random.nextBytes(data); RandomAccessBucket bucket = new SimpleReadOnlyArrayBucket(data); FreenetURI uri = InsertableClientSSK.createRandom(random, "test").getInsertURI(); return new InsertBlock(bucket, new ClientMetadata(null), uri); }
System.out.println("Insert/retrieve test"); System.out.println(); DummyRandomSource random = new DummyRandomSource(3142); DummyRandomSource topologyRandom = new DummyRandomSource(3143); waitForPingAverage(0.5, nodes, new DummyRandomSource(3143), MAX_PINGS, 1000); random = new DummyRandomSource(3144);
int block; do { block = random.nextInt(total); } while (hits[block]); hits[block] = true;
DummyRandomSource random = new DummyRandomSource(3142); waitForPingAverage(0.98, nodes, new DummyRandomSource(3143), MAX_PINGS, 5000); System.exit(0);
int block; do { block = random.nextInt(total); } while (hits[block]); hits[block] = true;
private void setupSone(Sone sone, Class<? extends Identity> identityClass) { Identity identity = mock(identityClass); InsertableClientSSK clientSSK = createRandom(new DummyRandomSource(), "WoT"); when(identity.getRequestUri()).thenReturn(clientSSK.getURI().toString()); when(identity.getId()).thenReturn("identity"); when(sone.getId()).thenReturn("identity"); when(sone.getIdentity()).thenReturn(identity); requestUri = clientSSK.getURI().setKeyType("USK").setDocName("Sone"); when(sone.getRequestUri()).thenAnswer(new Answer<FreenetURI>() { @Override public FreenetURI answer(InvocationOnMock invocation) throws Throwable { return requestUri; } }); when(sone.getTime()) .thenReturn(currentTimeMillis() - DAYS.toMillis(1)); }
@Before public void setupSone() { Sone sone = SoneDownloaderTest.this.sone; Identity identity = mock(Identity.class); InsertableClientSSK clientSSK = createRandom(new DummyRandomSource(), "WoT"); when(identity.getRequestUri()).thenReturn(clientSSK.getURI().toString()); when(identity.getId()).thenReturn("identity"); when(sone.getId()).thenReturn("identity"); when(sone.getIdentity()).thenReturn(identity); requestUri = clientSSK.getURI().setKeyType("USK").setDocName("Sone"); when(sone.getRequestUri()).thenAnswer(new Answer<FreenetURI>() { @Override public FreenetURI answer(InvocationOnMock invocation) throws Throwable { return requestUri; } }); when(sone.getTime()).thenReturn(currentTimeMillis() - DAYS.toMillis(1)); }
@Test public void returnedUriHasCorrectDocNameAndMetaStrings() { FreenetURI uri = createRandom(new DummyRandomSource(), "test-0").getURI().uskForSSK(); assertThat(create(uri.toString()).getDocName(), is("Sone")); assertThat(create(uri.toString()).getAllMetaStrings(), is(new String[0])); }
private void testRestart(String password) throws MasterKeysWrongPasswordException, MasterKeysFileSizeException, IOException { File keysFile = new File(base, "test.master.keys"); DummyRandomSource random = new DummyRandomSource(77391); MasterKeys original = MasterKeys.read(keysFile, random, password); byte[] clientCacheMasterKey = original.clientCacheMasterKey; DatabaseKey dkey = original.createDatabaseKey(random); MasterSecret tempfileMasterSecret = original.getPersistentMasterSecret(); MasterKeys restored = MasterKeys.read(keysFile, random, password); assertArrayEquals(clientCacheMasterKey, restored.clientCacheMasterKey); assertEquals(dkey,restored.createDatabaseKey(random)); assertEquals(tempfileMasterSecret, restored.getPersistentMasterSecret()); }
private void testChangePassword(String oldPassword, String newPassword) throws MasterKeysWrongPasswordException, MasterKeysFileSizeException, IOException { File keysFile = new File(base, "test.master.keys"); DummyRandomSource random = new DummyRandomSource(77391); MasterKeys original = MasterKeys.read(keysFile, random, oldPassword); byte[] clientCacheMasterKey = original.clientCacheMasterKey; DatabaseKey dkey = original.createDatabaseKey(random); MasterSecret tempfileMasterSecret = original.getPersistentMasterSecret(); // Change password. original.changePassword(keysFile, newPassword, random); // Now restore. if(!oldPassword.equals(newPassword)) { try { MasterKeys.read(keysFile, random, oldPassword); fail("Old password should not work!"); } catch (MasterKeysWrongPasswordException e) { // Ok. } } MasterKeys restored = MasterKeys.read(keysFile, random, newPassword); assertArrayEquals(clientCacheMasterKey, restored.clientCacheMasterKey); assertEquals(dkey,restored.createDatabaseKey(random)); assertEquals(tempfileMasterSecret, restored.getPersistentMasterSecret()); }
public ClientRequestSelectorTest() throws IOException { dir = new File("split-file-inserter-storage-test"); dir.mkdir(); executor = new WaitableExecutor(new PooledExecutor()); ticker = new CheatingTicker(executor); RandomSource r = new DummyRandomSource(12345); fg = new FilenameGenerator(r, true, dir, "freenet-test"); persistentFileTracker = new TrivialPersistentFileTracker(dir, fg); bigRAFFactory = new PooledFileRandomAccessBufferFactory(fg, r); smallBucketFactory = new ArrayBucketFactory(); bigBucketFactory = new TempBucketFactory(executor, fg, 0, 0, r, false, 0, null); baseContext = HighLevelSimpleClientImpl.makeDefaultInsertContext(bigBucketFactory, new SimpleEventProducer()); cryptoKey = new byte[32]; r.nextBytes(cryptoKey); checker = new CRCChecksumChecker(); memoryLimitedJobRunner = new MemoryLimitedJobRunner(9*1024*1024L, 20, executor, NativeThread.JAVA_PRIORITY_RANGE); jobRunner = new DummyJobRunner(executor, null); URI = FreenetURI.generateRandomCHK(r); }
public SplitFileInserterStorageTest() throws IOException { dir = new File("split-file-inserter-storage-test"); dir.mkdir(); executor = new WaitableExecutor(new PooledExecutor()); ticker = new CheatingTicker(executor); RandomSource r = new DummyRandomSource(12345); fg = new FilenameGenerator(r, true, dir, "freenet-test"); persistentFileTracker = new TrivialPersistentFileTracker(dir, fg); bigRAFFactory = new PooledFileRandomAccessBufferFactory(fg, r); smallBucketFactory = new ArrayBucketFactory(); bigBucketFactory = new TempBucketFactory(executor, fg, 0, 0, r, false, 0, null); baseContext = HighLevelSimpleClientImpl.makeDefaultInsertContext(bigBucketFactory, new SimpleEventProducer()); cryptoKey = new byte[32]; r.nextBytes(cryptoKey); checker = new CRCChecksumChecker(); memoryLimitedJobRunner = new MemoryLimitedJobRunner(9*1024*1024L, 20, executor, NativeThread.JAVA_PRIORITY_RANGE); jobRunner = new DummyJobRunner(executor, null); URI = FreenetURI.generateRandomCHK(r); }