/** * Validate if BusinessObjectQuery returns business objects which are defined in the models * MODEL_NAME2 and MODEL_NAME3. Note: If BusinessObjectsList is executed standalone than * bos.size() == expected.size(). But if it is executed after CheckFiltering2 then bos.size() > * expected.size() because CheckFiltering2 deployes MODEL_NAME3 as a new version. This means that * bos.size() == expected.size()+2 in this case. */ @Test public void BusinessObjectsList() { BusinessObjectQuery query = BusinessObjectQuery.findAll(); query.setPolicy(new BusinessObjectQuery.Policy(BusinessObjectQuery.Option.WITH_DESCRIPTION)); BusinessObjects bos = sf.getQueryService().getAllBusinessObjects(query); List<String> expected = CollectionUtils.newArrayListFromElements( Arrays.asList( new QName(MODEL_NAME2, "Account").toString(), new QName(MODEL_NAME2, "Customer").toString(), new QName(MODEL_NAME2, "Order").toString(), new QName(MODEL_NAME2, "Fund").toString(), new QName(MODEL_NAME2, "FundGroup").toString(), new QName(MODEL_NAME3, "Employee").toString(), new QName(MODEL_NAME3, "Fund").toString())); List<String> removedEntries = CollectionUtils.newArrayList(expected.size()); for (BusinessObject bo : bos) { String qualifiedBOId = new QName(bo.getModelId(), bo.getId()).toString(); if (expected.remove(qualifiedBOId)) { removedEntries.add(qualifiedBOId); } else { Assert.assertTrue( "Not expected entry: " + qualifiedBOId, removedEntries.contains(qualifiedBOId)); } } Assert.assertTrue("Missing business objects: " + expected, expected.isEmpty()); }
@Test public void testIterable2() { addFromArray(this.set, this.keyE, this.key1, this.key2, this.key2, this.key3, this.key4); this.set.remove(this.k2); Assert.assertEquals(4, this.set.size()); int counted = 0; for (final KTypeCursor<KType> cursor : this.set) { if (cursor.index == getKeys(this.set).length) { Assert.assertTrue(this.isAllocatedDefaultKey(this.set)); TestUtils.assertEquals2(this.keyE, cursor.value); counted++; continue; } Assert.assertTrue(this.set.contains(cursor.value)); TestUtils.assertEquals2(cursor.value, this.getKeys(this.set)[cursor.index]); counted++; } Assert.assertEquals(counted, this.set.size()); this.set.clear(); Assert.assertFalse(this.set.iterator().hasNext()); }
/** * Check that the set is consistent, i.e all allocated slots are reachable by get(), and all * not-allocated contains nulls if Generic * * @param set */ @After public void checkConsistency() { if (this.set != null) { int occupied = 0; final int mask = getKeys(this.set).length - 1; for (int i = 0; i < getKeys(this.set).length; i++) { if (!is_allocated(i, Intrinsics.<KType[]>cast(getKeys(this.set)))) { // if not allocated, generic version if patched to null for GC sake /*! #if ($TemplateOptions.KTypeGeneric) !*/ TestUtils.assertEquals2(this.keyE, getKeys(this.set)[i]); /*! #end !*/ } else { // try to reach the key by contains() Assert.assertTrue(this.set.contains(Intrinsics.<KType>cast(getKeys(this.set)[i]))); occupied++; } } if (isAllocatedDefaultKey(this.set)) { // try to reach the key by contains() Assert.assertTrue(this.set.contains(this.keyE)); occupied++; } Assert.assertEquals(occupied, this.set.size()); } }
/** * Run some random insertions/ deletions and compare the results against <code>java.util.HashSet * </code>. */ @Test public void testAgainstHashMap() { final java.util.Random rnd = new Random(0xBADCAFE); final java.util.HashSet<KType> other = new java.util.HashSet<KType>(); for (int size = 1000; size < 20000; size += 4000) { other.clear(); this.set.clear(); for (int round = 0; round < size * 20; round++) { final KType key = cast(rnd.nextInt(size)); if (rnd.nextBoolean()) { other.add(key); this.set.add(key); Assert.assertTrue(this.set.contains(key)); } else { Assert.assertTrue( "size= " + size + ", round = " + round, other.remove(key) == this.set.remove(key)); } Assert.assertEquals(other.size(), this.set.size()); } } }
@Test public void testNullKey() { this.set.add((KType) null); Assert.assertEquals(1, this.set.size()); Assert.assertTrue(this.set.contains(null)); Assert.assertTrue(this.set.remove(null)); Assert.assertEquals(0, this.set.size()); Assert.assertFalse(this.set.contains(null)); }
@Test public void listRequest() { JdbcContentPersistenceService tested = getTested(); tested.LIST_PAGE_SIZE = 3; String sysContentType = "testtypelist"; // case - no table exists for type { ListRequest req = tested.listRequestInit(sysContentType); Assert.assertFalse(req.hasContent()); } // case - data handling test { // store in reverse order to see if listing uses correct ordering for (int i = 7; i >= 1; i--) addContent(tested, sysContentType, "aaa-" + i); ListRequest req = tested.listRequestInit(sysContentType); Assert.assertTrue(req.hasContent()); Assert.assertNotNull(req.content()); Assert.assertEquals(3, req.content().size()); Assert.assertEquals("aaa-1", req.content().get(0).getId()); // assert content is correctly loaded Assert.assertEquals( "aaa-1", req.content().get(0).getContent().get(ContentObjectFields.SYS_ID)); Assert.assertEquals( "value aaa-1", req.content().get(0).getContent().get(ContentObjectFields.SYS_DESCRIPTION)); // assert id only for others Assert.assertEquals("aaa-2", req.content().get(1).getId()); Assert.assertEquals("aaa-3", req.content().get(2).getId()); req = tested.listRequestNext(req); Assert.assertTrue(req.hasContent()); Assert.assertNotNull(req.content()); Assert.assertEquals(3, req.content().size()); Assert.assertEquals("aaa-4", req.content().get(0).getId()); Assert.assertEquals("aaa-5", req.content().get(1).getId()); Assert.assertEquals("aaa-6", req.content().get(2).getId()); req = tested.listRequestNext(req); Assert.assertTrue(req.hasContent()); Assert.assertNotNull(req.content()); Assert.assertEquals(1, req.content().size()); Assert.assertEquals("aaa-7", req.content().get(0).getId()); req = tested.listRequestNext(req); Assert.assertFalse(req.hasContent()); } }
@Test public void testFlatMapMaxConcurrent() { final int m = 4; final AtomicInteger subscriptionCount = new AtomicInteger(); Observable<Integer> source = Observable.range(1, 10) .flatMap( new Func1<Integer, Observable<Integer>>() { @Override public Observable<Integer> call(Integer t1) { return compose(Observable.range(t1 * 10, 2), subscriptionCount, m) .subscribeOn(Schedulers.computation()); } }, m); TestSubscriber<Integer> ts = new TestSubscriber<Integer>(); source.subscribe(ts); ts.awaitTerminalEvent(); ts.assertNoErrors(); Set<Integer> expected = new HashSet<Integer>( Arrays.asList( 10, 11, 20, 21, 30, 31, 40, 41, 50, 51, 60, 61, 70, 71, 80, 81, 90, 91, 100, 101)); Assert.assertEquals(expected.size(), ts.getOnNextEvents().size()); Assert.assertTrue(expected.containsAll(ts.getOnNextEvents())); }
// Look up a previously instantiated SubSequence relationship. public static SubSequence find(PptSlice ppt) { Assert.assertTrue(ppt.arity() == 2); for (Invariant inv : ppt.invs) { if (inv instanceof SubSequence) return (SubSequence) inv; } return null; }
private void assertTableContent( final JdbcContentPersistenceService tested, final String sysContentType, final String id, final Date expectedUpdated) { final String tablename = tested.getTableName(sysContentType); try (final Connection conn = this.getTested().searchiskoDs.getConnection(); final PreparedStatement statement = conn.prepareStatement( String.format( "select sys_content_type, updated from %s where id = ?", tablename))) { statement.setString(1, id); try (final ResultSet rs = statement.executeQuery()) { Assert.assertTrue(rs.next()); Assert.assertEquals(sysContentType, rs.getString(1)); Timestamp actualTimestamp = rs.getTimestamp(2); if (expectedUpdated != null) { Assert.assertEquals(new Timestamp(expectedUpdated.getTime()), actualTimestamp); } else { Assert.assertNotNull(actualTimestamp); } } } catch (SQLException e) { Assert.fail(e.getMessage()); } }
@Test public void testConnectionResetByHttpClientUtils() throws IOException { testConnectionResetCount = 0; httpClientUtils = new HttpClientUtils(); httpClientUtils.initHttpClient(); Logger.info(this, "-------------- HttpClient initialized -------------"); String resp = null; try { resp = httpClientUtils.get("http://localhost:65532/soso"); } catch (IOException e) { Throwable ee = ExceptionUtils.getRootCause(e); if (ee == null) { ee = e; } Logger.error(this, "", ee); Assert.assertNotSame(NoHttpResponseException.class, ee.getClass()); Assert.assertSame(SocketException.class, ee.getClass()); Assert.assertTrue( "Connection reset".equals(ee.getMessage()) || "Socket closed".equals(ee.getMessage()) || "Unexpected end of file from server".equals(ee.getMessage())); } finally { Logger.info( this, "resp[HttpURLConnection]-[" + testConnectionResetCount + "]=========[" + resp + "]========="); } Assert.assertEquals(1, testConnectionResetCount); }
/** * 运行时,添加JVM参数“-Dsun.net.http.retryPost=false”,可阻止自动重连。 * * @see 'http://www.coderanch.com/t/490463/sockets/java/Timeout-retry-URLHTTPRequest' */ @Test public void testConnectionResetByHttpURLConnection() throws IOException { testConnectionResetCount = 0; String resp = null; try { HttpURLConnection conn = (HttpURLConnection) new URL("http://localhost:65532/soso").openConnection(); conn.setDoOutput(true); conn.setRequestMethod("POST"); conn.getOutputStream().write("username".getBytes()); resp = conn.getResponseCode() + ""; } catch (IOException e) { Throwable ee = ExceptionUtils.getRootCause(e); if (ee == null) { ee = e; } Logger.error(this, "", ee); Assert.assertNotSame(NoHttpResponseException.class, ee.getClass()); Assert.assertSame(SocketException.class, ee.getClass()); Assert.assertTrue( "Connection reset".equals(ee.getMessage()) || "Socket closed".equals(ee.getMessage()) || "Unexpected end of file from server".equals(ee.getMessage())); } finally { Logger.info( this, "resp[HttpURLConnection]-[" + testConnectionResetCount + "]=========[" + resp + "]========="); } Assert.assertEquals(2, testConnectionResetCount); }
@Test public void testAdd() { Assert.assertTrue(this.set.add(this.key1)); Assert.assertFalse(this.set.add(this.key1)); Assert.assertEquals(1, this.set.size()); Assert.assertTrue(this.set.add(this.keyE)); Assert.assertFalse(this.set.add(this.keyE)); Assert.assertEquals(2, this.set.size()); Assert.assertTrue(this.set.add(this.key2)); Assert.assertFalse(this.set.add(this.key2)); Assert.assertEquals(3, this.set.size()); }
// Look up a previously instantiated invariant. public static EltwiseIntEqual find(PptSlice ppt) { Assert.assertTrue(ppt.arity() == 1); for (Invariant inv : ppt.invs) { if (inv instanceof EltwiseIntEqual) return (EltwiseIntEqual) inv; } return null; }
/** * process the sample by checking it against each existing invariant and issuing an error if any * invariant is falsified or weakened. */ public void process_sample(PptMap all_ppts, PptTopLevel ppt, ValueTuple vt, Integer nonce) { this.all_ppts = all_ppts; debug.fine("processing sample from: " + ppt.name); // Add orig and derived variables FileIO.add_orig_variables(ppt, vt.vals, vt.mods, nonce); FileIO.add_derived_variables(ppt, vt.vals, vt.mods); // Intern the sample vt = new ValueTuple(vt.vals, vt.mods); // If this is an enter point, just remember it for later if (ppt.ppt_name.isEnterPoint()) { Assert.assertTrue(nonce != null); if (dir_file != null) { // Yoav: I had to do a hack to handle the case that several dtrace files are concatenated // together, // and Sung's dtrace files have unterminated calls, and when concatenating two files you // can have the same nonce. // So I have to remove the nonce found from the call_map call_map.remove(nonce); } else Assert.assertTrue(call_map.get(nonce) == null); call_map.put(nonce, new EnterCall(ppt, vt)); debug.fine("Skipping enter sample"); return; } // If this is an exit point, process the saved enter point if (ppt.ppt_name.isExitPoint()) { Assert.assertTrue(nonce != null); EnterCall ec = call_map.get(nonce); if (ec != null) { call_map.remove(nonce); debug.fine("Processing enter sample from " + ec.ppt.name); add(ec.ppt, ec.vt); } else { // didn't find the enter if (!quiet) System.out.printf("couldn't find enter for nonce %d at ppt %s\n", nonce, ppt.name()); return; } } add(ppt, vt); }
@Test public void simulateClusterTableCreation() { JdbcContentPersistenceService tested = getTested(); Assert.assertFalse(tested.checkTableExists("table1")); createTable("TABLE1"); Assert.assertTrue(tested.checkTableExists("table1")); }
public void assertTrue(boolean b) { try { Assert.assertTrue(b); } catch (Error e) { lastTestFailed = true; throw e; } }
@Test public void checkAndEnsureTableExists() { JdbcContentPersistenceService tested = getTested(); Assert.assertFalse(tested.checkTableExists("table1")); Assert.assertFalse(tested.checkTableExists("table1")); tested.ensureTableExists("table1"); Assert.assertTrue(tested.checkTableExists("table1")); tested.ensureTableExists("table1"); Assert.assertTrue(tested.checkTableExists("table1")); Assert.assertTrue(tested.checkTableExists("table1")); Assert.assertFalse(tested.checkTableExists("table_2")); tested.ensureTableExists("table_2"); Assert.assertTrue(tested.checkTableExists("table_2")); Assert.assertTrue(tested.checkTableExists("table1")); }
@Test public void testPooledIteratorBrokenForEach() { // A) for-each loop interrupted // must accommodate even the smallest primitive type // so that the iteration do not break before it should... final int TEST_SIZE = 126; final long TEST_ROUNDS = 5000; final KTypeSet<KType> testContainer = createSetWithOrderedData(TEST_SIZE); int count = 0; for (int round = 0; round < TEST_ROUNDS; round++) { // for-each in test : final long initialPoolSize = getEntryPoolSize(testContainer); count = 0; int guard = 0; for (final KTypeCursor<KType> cursor : testContainer) { guard += castType(cursor.value); // we consume 1 iterator for this loop, but reallocs can happen, // so we can only say its != initialPoolSize Assert.assertTrue(initialPoolSize != getEntryPoolSize(testContainer)); // brutally interrupt in the middle if (count > TEST_SIZE / 2) { break; } count++; } // end for-each // iterator is NOT returned to its pool, due to the break. // reallocation could happen, so that the only testable thing // is that the size is != full pool Assert.assertTrue(initialPoolSize != getEntryPoolSize(testContainer)); } // end for rounds // Due to policy of the Iterator pool, the intended pool never get bigger that some limit // despite the Iterator leak. Assert.assertTrue(getEntryPoolCapacity(testContainer) < IteratorPool.getMaxPoolSize() + 1); }
public void runTest( final String url, final int urlGroupSize, final ExceptionHandler exceptionHandler, int threadCount) { ok = true; long beginTime = System.currentTimeMillis(); ArrayList<Thread> list = new ArrayList<Thread>(); for (int t = 1; t <= threadCount; t++) { Thread tt = new Thread(url + "_runTest_" + t) { @Override public void run() { boolean useGroup = urlGroupSize > 1; for (int i = 1; i <= urlGroupSize; i++) { if (!ok) return; String resp = null; Throwable t = null; try { if (useGroup) { resp = httpClientUtils.get(url + i); } else { resp = httpClientUtils.get(url); } } catch (Throwable e) { Throwable ee = ExceptionUtils.getRootCause(e); if (ee == null) { ee = e; } Logger.error(this, "", ee); t = ee; } finally { if (ok) { ok = exceptionHandler.handle(t); } } Logger.info(this, "resp[" + i + "]=========[" + resp + "]========="); } } }; list.add(tt); tt.start(); } for (Thread tt : list) { try { tt.join(); } catch (InterruptedException e) { throw new RuntimeException(e); } } Assert.assertTrue(ok); Logger.info(this, "take time milliseconds: " + (System.currentTimeMillis() - beginTime)); }
@Test public void testAtomicCommitExistingFinal() { TaskAttemptContext taskAttemptContext = getTaskAttemptContext(config); JobContext jobContext = new JobContextImpl( taskAttemptContext.getConfiguration(), taskAttemptContext.getTaskAttemptID().getJobID()); Configuration conf = jobContext.getConfiguration(); String workPath = "/tmp1/" + String.valueOf(rand.nextLong()); String finalPath = "/tmp1/" + String.valueOf(rand.nextLong()); FileSystem fs = null; try { OutputCommitter committer = new CopyCommitter(null, taskAttemptContext); fs = FileSystem.get(conf); fs.mkdirs(new Path(workPath)); fs.mkdirs(new Path(finalPath)); conf.set(DistCpConstants.CONF_LABEL_TARGET_WORK_PATH, workPath); conf.set(DistCpConstants.CONF_LABEL_TARGET_FINAL_PATH, finalPath); conf.setBoolean(DistCpConstants.CONF_LABEL_ATOMIC_COPY, true); Assert.assertTrue(fs.exists(new Path(workPath))); Assert.assertTrue(fs.exists(new Path(finalPath))); try { committer.commitJob(jobContext); Assert.fail("Should not be able to atomic-commit to pre-existing path."); } catch (Exception exception) { Assert.assertTrue(fs.exists(new Path(workPath))); Assert.assertTrue(fs.exists(new Path(finalPath))); LOG.info("Atomic-commit Test pass."); } } catch (IOException e) { LOG.error("Exception encountered while testing for atomic commit.", e); Assert.fail("Atomic commit failure"); } finally { TestDistCpUtils.delete(fs, workPath); TestDistCpUtils.delete(fs, finalPath); } }
@Test public void testRemove() { Assert.assertFalse(this.set.remove(this.k2)); Assert.assertFalse(this.set.remove(this.keyE)); addFromArray(this.set, this.key0, this.key1, this.key2, this.key3, this.key4); Assert.assertTrue(this.set.remove(this.k2)); Assert.assertFalse(this.set.remove(this.k2)); Assert.assertEquals(4, this.set.size()); TestUtils.assertSortedListEquals(this.set.toArray(), 0, 1, 3, 4); }
@Test public void testTopologicalSort() { final Set<Object> nodes = new HashSet<Object>(); final Object centerNode = "centerNode"; nodes.add(centerNode); final Object topNode = "topNode"; nodes.add(topNode); final Object leftNode = "leftNode"; nodes.add(leftNode); final Object leftiestNode = "leftiestNode"; nodes.add(leftiestNode); final Object rightNode = "rightNode"; nodes.add(rightNode); final Set<DirectedEdge<Object>> edges = new HashSet<DirectedEdge<Object>>(); final DirectedEdge<Object> centerTopEdge = new ImmutableDirectedEdge<Object>(centerNode, topNode); edges.add(centerTopEdge); final DirectedEdge<Object> centerLeftEdge = new ImmutableDirectedEdge<Object>(centerNode, leftNode); edges.add(centerLeftEdge); final DirectedEdge<Object> leftLeftiestEdge = new ImmutableDirectedEdge<Object>(leftNode, leftiestNode); edges.add(leftLeftiestEdge); final DirectedEdge<Object> centerRightEdge = new ImmutableDirectedEdge<Object>(centerNode, rightNode); edges.add(centerRightEdge); final BidirectedGraph<Object, DirectedEdge<Object>> graph = new ImmutableDirectedAdjacencyGraph<Object, DirectedEdge<Object>>(nodes, edges); final TopologicalSorter<Object> sorter = new SimpleTopologicalRanker<Object>(); final List<Object> sortedNodes = sorter.sort(graph); Assert.assertTrue("center node is not the first node!", sortedNodes.get(0) == centerNode); Assert.assertTrue( "left node is not before leftiest node!", sortedNodes.indexOf(leftNode) < sortedNodes.indexOf(leftiestNode)); }
@Repeat(iterations = 10) @Test public void testPreallocatedSize() { final Random randomVK = RandomizedTest.getRandom(); // Test that the container do not resize if less that the initial size // 1) Choose a random number of elements /*! #if ($TemplateOptions.isKType("GENERIC", "INT", "LONG", "FLOAT", "DOUBLE")) !*/ final int PREALLOCATED_SIZE = randomVK.nextInt(10000); /*! #elseif ($TemplateOptions.isKType("SHORT", "CHAR")) int PREALLOCATED_SIZE = randomVK.nextInt(1500); #else int PREALLOCATED_SIZE = randomVK.nextInt(126); #end !*/ final KTypeSet<KType> newSet = createNewSetInstance(PREALLOCATED_SIZE, HashContainers.DEFAULT_LOAD_FACTOR); // computed real capacity final int realCapacity = newSet.capacity(); // 3) Add PREALLOCATED_SIZE different values. At the end, size() must be == realCapacity, // and internal buffer/allocated must not have changed of size final int contructorBufferSize = getKeys(newSet).length; Assert.assertEquals(contructorBufferSize, getKeys(newSet).length); for (int i = 0; i < 1.5 * realCapacity; i++) { newSet.add(cast(i)); // internal size has not changed until realCapacity if (newSet.size() <= realCapacity) { Assert.assertEquals(contructorBufferSize, getKeys(newSet).length); } if (contructorBufferSize < getKeys(newSet).length) { // The container as just reallocated, its actual size must be not too far from the previous // capacity: Assert.assertTrue( "Container as reallocated at size = " + newSet.size() + " with previous capacity = " + realCapacity, (newSet.size() - realCapacity) <= 3); break; } } }
@Test public void testPostCustomerBodyAndCharset() { httpClientUtils = new HttpClientUtils(); httpClientUtils.initHttpClient(); Logger.info(this, "-------------- HttpClient initialized -------------"); // testPostCustomerBodyAndCharset String resp = ""; try { resp = httpClientUtils.post( "http://localhost:65534/test/testPostCustomerBodyAndCharset", "<?xml version=\"1.0\" encoding=\"GBK\"?><AIPG><INFO>你好</INFO></AIPG>", "GBK"); } catch (IOException e) { Throwable ee = ExceptionUtils.getRootCause(e); if (ee == null) { ee = e; } Logger.error(this, "", ee); Assert.assertTrue(false); // Assert.assertNotSame(NoHttpResponseException.class, ee.getClass()); // Assert.assertSame(SocketException.class, ee.getClass()); // Assert.assertTrue("Connection reset".equals(ee.getMessage()) || "Socket // closed".equals(ee.getMessage()) || "Unexpected end of file from // server".equals(ee.getMessage())); } finally { Logger.info( this, "resp[HttpURLConnection]-[" + testConnectionResetCount + "]=========[" + resp + "]========="); } // Assert.assertEquals(1, testConnectionResetCount); Assert.assertTrue(true); }
private void checkValue( List<BusinessObject.Value> boValues, boolean strict, String name, Object... values) { Set<Object> expected = CollectionUtils.newSetFromIterator(Arrays.asList(values).iterator()); Set<Object> actual = CollectionUtils.newSet(); for (BusinessObject.Value boValue : boValues) { Map<?, ?> data = (Map<?, ?>) boValue.getValue(); actual.add(data.get(name)); } if (strict) { Assert.assertEquals("Values: ", expected, actual); } else { expected.removeAll(actual); Assert.assertTrue("Missing values: " + expected, expected.isEmpty()); } }
/** * Test if the business object query returns all business object instances for a given business * object id. The BO instances was created by the OrderCreation process resp. EnterOrderData * activity in the setup() method. */ @Test public void CheckOrders() { DeployedModelDescription model = sf.getQueryService().getModels(DeployedModelQuery.findActiveForId(MODEL_NAME2)).get(0); BusinessObjectQuery query = BusinessObjectQuery.findForBusinessObject(new QName(model.getId(), "Order").toString()); query.setPolicy(new BusinessObjectQuery.Policy(BusinessObjectQuery.Option.WITH_VALUES)); BusinessObjects bos = sf.getQueryService().getAllBusinessObjects(query); Assert.assertEquals("Objects", 1, bos.getSize()); BusinessObject bo = bos.get(0); List<BusinessObject.Value> values = bo.getValues(); Assert.assertTrue("Expected at least 5 values: " + values.size(), 5 <= values.size()); checkValue(values, false, "customerId", 1, 2, 3, 4, 5); }
@Test public void requestSignatureTest() throws Exception { String envelopeId = ""; // will retrieve // // Step 1 - login // DocuSignClient client = new DocuSignClient( TestSettings.TEST_EMAIL, TestSettings.TEST_PASSWORD, TestSettings.TEST_INTEGRATOR_KEY); boolean result = client.login(); Assert.assertTrue("login should work", result); // // STEP 2 - Send signature request from template // RequestSignatureFromTemplate request = new RequestSignatureFromTemplate(); request.setEmailSubject("From a Unit Test"); request.setEmailBlurb("Blurb from a Unit Test"); request.setTemplateId(TestSettings.TEMPLATE_ID); request.setStatus("sent"); // need to fill out who signs this TemplateRole role = new TemplateRole(); role.setName("Mike Borozdin"); role.setEmail(TestSettings.SAMPLE_EMAIL); role.setRoleName("Signer1"); List<TemplateRole> roles = new ArrayList<TemplateRole>(1); roles.add(role); request.setTemplateRoles(roles); RequestSignatureResponse response = client.requestSignatureFromTemplate(request); Assert.assertNotNull(response); envelopeId = response.getEnvelopeId(); System.out.println("envelopeId = " + envelopeId); }
@Test public void testRemoveAllWithPredicateInterrupted() { addFromArray( this.set, newArray(this.k0, this.k1, this.k2, this.k3, this.k4, this.k5, this.k6, this.k7, this.k8)); final RuntimeException t = new RuntimeException(); try { // the assert below should never be triggered because of the exception // so give it an invalid value in case the thing terminates = initial size + 1 Assert.assertEquals( 10, this.set.removeAll( new KTypePredicate<KType>() { @Override public boolean apply(final KType v) { if (v == AbstractKTypeHashSetTest.this.key7) { throw t; } return v == AbstractKTypeHashSetTest.this.key2 || v == AbstractKTypeHashSetTest.this.key9 || v == AbstractKTypeHashSetTest.this.key5; }; })); Assert.fail(); } catch (final RuntimeException e) { // Make sure it's really our exception... if (e != t) { throw e; } } // And check if the set is in consistent state. We cannot predict the pattern, // but we know that since key7 throws an exception, key7 is still present in the set. Assert.assertTrue(this.set.contains(this.key7)); checkConsistency(); }
public boolean isSameFormula(Invariant inv) { Assert.assertTrue(inv instanceof SubSequence); return (true); }
/** * Returns true if the two original variables are related in a way that makes subsequence or * subset detection not informative. */ public static boolean isObviousSubSequenceDynamically( Invariant inv, VarInfo subvar, VarInfo supervar) { VarInfo[] vis = {subvar, supervar}; ProglangType rep1 = subvar.rep_type; ProglangType rep2 = supervar.rep_type; if (!(((rep1 == ProglangType.INT_ARRAY) && (rep2 == ProglangType.INT_ARRAY)) || ((rep1 == ProglangType.DOUBLE_ARRAY) && (rep2 == ProglangType.DOUBLE_ARRAY)) || ((rep1 == ProglangType.STRING_ARRAY) && (rep2 == ProglangType.STRING_ARRAY)))) return false; if (debug.isLoggable(Level.FINE)) { debug.fine( "Checking isObviousSubSequenceDynamically " + subvar.name() + " in " + supervar.name()); } Object[] di = isObviousSubSequence(subvar, supervar); if (di[1] != null) { inv.log("ObvSubSeq- true from isObviousSubSequence: " + di[1]); return true; } debug.fine(" not isObviousSubSequence(statically)"); PptTopLevel ppt_parent = subvar.ppt; // If the elements of supervar are always the same (EltOneOf), // we aren't going to learn anything new from this invariant, // since each sequence should have an EltOneOf over it. if (false) { PptSlice1 slice = ppt_parent.findSlice(supervar); if (slice == null) { System.out.println("No slice: parent =" + ppt_parent); } else { System.out.println("Slice var =" + slice.var_infos[0]); for (Invariant superinv : slice.invs) { System.out.println("Inv = " + superinv); if (superinv instanceof EltOneOf) { EltOneOf eltinv = (EltOneOf) superinv; if (eltinv.num_elts() > 0) { inv.log(" obvious because of " + eltinv.format()); return true; } } } } } // Obvious if subvar is always just [] if (true) { PptSlice1 slice = ppt_parent.findSlice(subvar); if (slice != null) { for (Invariant subinv : slice.invs) { if (subinv instanceof OneOfSequence) { OneOfSequence seqinv = (OneOfSequence) subinv; if (seqinv.num_elts() == 1) { Object elt = seqinv.elt(); if (elt instanceof long[] && ((long[]) elt).length == 0) { Debug.log( debug, inv.getClass(), inv.ppt, vis, "ObvSubSeq- True from subvar being []"); return true; } if (elt instanceof double[] && ((double[]) elt).length == 0) { inv.log("ObvSubSeq- True from subvar being []"); return true; } } } } } } // Check for a[0..i] subseq a[0..j] but i < j. VarInfo subvar_super = subvar.isDerivedSubSequenceOf(); VarInfo supervar_super = supervar.isDerivedSubSequenceOf(); if (subvar_super != null && subvar_super == supervar_super) { // both sequences are derived from the same supersequence if ((subvar.derived instanceof SequenceScalarSubsequence || subvar.derived instanceof SequenceScalarArbitrarySubsequence) && (supervar.derived instanceof SequenceScalarSubsequence || supervar.derived instanceof SequenceScalarArbitrarySubsequence)) { VarInfo sub_left_var = null, sub_right_var = null, super_left_var = null, super_right_var = null; // I'm careful not to access foo_shift unless foo_var has been set // to a non-null value, but Java is too stupid to recognize that. int sub_left_shift = 42, sub_right_shift = 69, super_left_shift = 1492, super_right_shift = 1776; if (subvar.derived instanceof SequenceScalarSubsequence) { SequenceScalarSubsequence sub = (SequenceScalarSubsequence) subvar.derived; if (sub.from_start) { sub_right_var = sub.sclvar(); sub_right_shift = sub.index_shift; } else { sub_left_var = sub.sclvar(); sub_left_shift = sub.index_shift; } } else if (subvar.derived instanceof SequenceScalarArbitrarySubsequence) { SequenceScalarArbitrarySubsequence sub = (SequenceScalarArbitrarySubsequence) subvar.derived; sub_left_var = sub.startvar(); sub_left_shift = (sub.left_closed ? 0 : 1); sub_right_var = sub.endvar(); sub_right_shift = (sub.right_closed ? 0 : -1); } else { Assert.assertTrue(false); } if (supervar.derived instanceof SequenceScalarSubsequence) { SequenceScalarSubsequence super_ = (SequenceScalarSubsequence) supervar.derived; if (super_.from_start) { super_right_var = super_.sclvar(); super_right_shift = super_.index_shift; } else { super_left_var = super_.sclvar(); super_left_shift = super_.index_shift; } } else if (supervar.derived instanceof SequenceScalarArbitrarySubsequence) { SequenceScalarArbitrarySubsequence super_ = (SequenceScalarArbitrarySubsequence) supervar.derived; super_left_var = super_.startvar(); super_left_shift = (super_.left_closed ? 0 : 1); super_right_var = super_.endvar(); super_right_shift = (super_.right_closed ? 0 : -1); } else { Assert.assertTrue(false); } boolean left_included, right_included; if (super_left_var == null) left_included = true; else if (sub_left_var == null) // we know super_left_var != null here left_included = false; else left_included = VarInfo.compare_vars( super_left_var, super_left_shift, sub_left_var, sub_left_shift, true /* <= */); if (super_right_var == null) right_included = true; else if (sub_right_var == null) // we know super_right_var != null here right_included = false; else right_included = VarInfo.compare_vars( super_right_var, super_right_shift, sub_right_var, sub_right_shift, false /* >= */); // System.out.println("Is " + subvar.name() + " contained in " // + supervar.name() // + "? left: " + left_included + ", right: " // + right_included); if (left_included && right_included) { inv.log("ObvSubSeq- True a[0..i] subseq a[0..j] and i < j"); return true; } } else if ((subvar.derived instanceof SequenceStringSubsequence) && (supervar.derived instanceof SequenceStringSubsequence)) { // Copied from just above SequenceStringSubsequence sss1 = (SequenceStringSubsequence) subvar.derived; SequenceStringSubsequence sss2 = (SequenceStringSubsequence) supervar.derived; VarInfo index1 = sss1.sclvar(); int shift1 = sss1.index_shift; boolean start1 = sss1.from_start; VarInfo index2 = sss2.sclvar(); int shift2 = sss2.index_shift; boolean start2 = sss2.from_start; if (start1 == start2) if (VarInfo.compare_vars(index1, shift1, index2, shift2, start1)) { inv.log("True from comparing indices"); return true; } } else { Assert.assertTrue( false, "how can this happen? " + subvar.name() + " " + subvar.derived.getClass() + " " + supervar.name() + " " + supervar.derived.getClass()); } } // Also need to check A[0..i] subseq A[0..j] via compare_vars. // A subseq B[0..n] => A subseq B List<Derivation> derivees = supervar.derivees(); // For each variable derived from supervar ("B") for (Derivation der : derivees) { // System.out.println(" ... der = " + der.getVarInfo().name() + " " + der); if (der instanceof SequenceScalarSubsequence) { // If that variable is "B[0..n]" VarInfo supervar_part = der.getVarInfo(); // Get the canonical version; being equal to it is good enough. if (supervar_part.get_equalitySet_leader() == subvar) { Debug.log(debug, inv.getClass(), inv.ppt, vis, "ObvSubSeq- True from canonical leader"); return true; } if (supervar_part.isCanonical()) { if (subvar == supervar_part) { System.err.println( "Error: variables " + subvar.name() + " and " + supervar_part.name() + " are identical. Canonical"); System.err.println(subvar.isCanonical()); System.err.println(supervar_part.isCanonical()); throw new Error(); } // Check to see if there is a subsequence over the supervar if (ppt_parent.is_subsequence(subvar, supervar_part)) { if (Debug.logOn()) inv.log( "ObvSubSeq- true from A subseq B[0..n] " + subvar.name() + "/" + supervar_part.name()); return (true); } } } } return false; }