connectTimeout in okhttp3 slows down responnse time - performance

Ho All,
I have a odd issue with okhttp version 4.9.0. It seems to increase the response time ( client.newCall(request).execute() ). If I increase the connectTimeout to 5 seconds the response time increases to 6 if I increase it to 15 seconds the response time increases to 16 seconds. Below is how I am using the builder.
client = new OkHttpClient.Builder()
.connectionPool(new ConnectionPool(2, 2, TimeUnit.SECONDS))
.cache(null)
.connectTimeout(2, TimeUnit.SECONDS)
.readTimeout(25, TimeUnit.SECONDS).build();
Thanks for any hints!

It is likely getting two or more routes and failing to connect to the first before the second one works. Most likely you have anetwork problem or similar and should fix that.
To confirm add a debugging EventListener
https://square.github.io/okhttp/events/
Since you haven't provided a useful reproduction, we can simulate using an additional route to test against.
val client = OkHttpClient.Builder()
.dns(object: Dns {
override fun lookup(hostname: String): List<InetAddress> {
return listOf<InetAddress>(InetAddress.getByName("198.51.100.0")) + Dns.SYSTEM.lookup("httpbin.org")
}
})
.eventListenerFactory(LoggingEventListener.Factory())
.build()
val response = client.newCall(Request.Builder().url("https://httpbin.org/get").build()).execute()
println(response.body!!.string())
Output will be like the following, not that the first connect takes 10 seconds (the connect timeouts) as it's hitting a dummy IP and then subsequent connections will try the second of the total 5 available IP addresses successfully and the request will continue.
Nov 23, 2020 7:44:01 AM okhttp3.internal.platform.Platform log
INFO: [0 ms] callStart: Request{method=GET, url=https://httpbin.org/get}
Nov 23, 2020 7:44:01 AM okhttp3.internal.platform.Platform log
INFO: [34 ms] proxySelectStart: https://httpbin.org/
Nov 23, 2020 7:44:01 AM okhttp3.internal.platform.Platform log
INFO: [35 ms] proxySelectEnd: [DIRECT]
Nov 23, 2020 7:44:01 AM okhttp3.internal.platform.Platform log
INFO: [36 ms] dnsStart: httpbin.org
Nov 23, 2020 7:44:01 AM okhttp3.internal.platform.Platform log
INFO: [150 ms] dnsEnd: [/198.51.100.0, httpbin.org/3.211.1.78, httpbin.org/35.170.225.136, httpbin.org/34.198.212.59, httpbin.org/52.6.34.179]
Nov 23, 2020 7:44:01 AM okhttp3.internal.platform.Platform log
INFO: [153 ms] connectStart: /198.51.100.0:443 DIRECT
Nov 23, 2020 7:44:11 AM okhttp3.internal.platform.Platform log
INFO: [10164 ms] connectFailed: null java.net.SocketTimeoutException: Connect timed out
Nov 23, 2020 7:44:11 AM okhttp3.internal.platform.Platform log
INFO: [10165 ms] connectStart: httpbin.org/3.211.1.78:443 DIRECT
Nov 23, 2020 7:44:11 AM okhttp3.internal.platform.Platform log
INFO: [10263 ms] secureConnectStart
Nov 23, 2020 7:44:12 AM okhttp3.internal.platform.Platform log
INFO: [10663 ms] secureConnectEnd: Handshake{tlsVersion=TLS_1_2 cipherSuite=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 peerCertificates=[CN=httpbin.org, CN=Amazon, OU=Server CA 1B, O=Amazon, C=US, CN=Amazon Root CA 1, O=Amazon, C=US] localCertificates=[]}
Nov 23, 2020 7:44:12 AM okhttp3.internal.platform.Platform log
INFO: [10676 ms] connectEnd: h2
Nov 23, 2020 7:44:12 AM okhttp3.internal.platform.Platform log
INFO: [10678 ms] connectionAcquired: Connection{httpbin.org:443, proxy=DIRECT hostAddress=httpbin.org/3.211.1.78:443 cipherSuite=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 protocol=h2}
Nov 23, 2020 7:44:12 AM okhttp3.internal.platform.Platform log
INFO: [10679 ms] requestHeadersStart
Nov 23, 2020 7:44:12 AM okhttp3.internal.platform.Platform log
INFO: [10683 ms] requestHeadersEnd
Nov 23, 2020 7:44:12 AM okhttp3.internal.platform.Platform log
INFO: [10903 ms] responseHeadersStart
Nov 23, 2020 7:44:12 AM okhttp3.internal.platform.Platform log
INFO: [10904 ms] responseHeadersEnd: Response{protocol=h2, code=200, message=, url=https://httpbin.org/get}
Nov 23, 2020 7:44:12 AM okhttp3.internal.platform.Platform log
INFO: [10907 ms] responseBodyStart
Nov 23, 2020 7:44:12 AM okhttp3.internal.platform.Platform log
INFO: [10908 ms] responseBodyEnd: byteCount=272
Nov 23, 2020 7:44:12 AM okhttp3.internal.platform.Platform log
INFO: [10908 ms] connectionReleased
Nov 23, 2020 7:44:12 AM okhttp3.internal.platform.Platform log
INFO: [10908 ms] callEnd
{
"args": {},
"headers": {
"Accept-Encoding": "gzip",
"Host": "httpbin.org",
"User-Agent": "okhttp/4.10.0-RC1",
"X-Amzn-Trace-Id": "Root=1-5fbb684d-0b7fa68f2cce945f25b5f1bf"
},
"origin": "81.100.210.134",
"url": "https://httpbin.org/get"
}

I ended up using a solution for Android mobile (smart device) when compiling to be compatible with java 1.8. Just add the below to your gradle.build file under defaultConfig section for the module where you use okhttp.
android.compileOptions.sourceCompatibility 1.8
android.compileOptions.targetCompatibility 1.8

Related

How to check if a date value inside an hash is bigger than a reference date

I'm writing a validation and I have an hash with this structure
elements.map{ |e| [e.id,e.coverable.published_at] }.to_h
=> {305=>Fri, 17 Apr 2020 15:23:00 CEST +02:00,
306=>Fri, 17 Apr 2020 13:00:00 CEST +02:00,
307=>Fri, 17 Apr 2020 09:20:00 CEST +02:00,
308=>Fri, 17 Apr 2020 12:59:00 CEST +02:00,
309=>Fri, 17 Apr 2020 11:39:00 CEST +02:00}
I have a reference date...
published_at
=> Mon, 04 May 2020 23:51:00 CEST +02:00
I have to check if any of the element has a published_at datetime value bigger than my published_at.
Is there a short way to do that?
Try something like this
elements.any? { |e| e.coverable.published_at > your_published_at }
In case you need the element which passes the condition use find
element = elements.find { |e| e.coverable.published_at > your_published_at }
# if element is not nil such element is present

Get min and max value from this array of hashes

I have an array that contains a hash in each row containing created_at and a value. How do I get the min and max from the array for the value fields?
The array is called - channels_counts_for_history_graph
and
channels_counts_for_history_graph.max[1]
Gives me the max date rather than the max value?
[[Sun, 30 Dec 2018 15:03:55 UTC +00:00, 4305],
[Sun, 30 Dec 2018 15:05:42 UTC +00:00, 4305],
[Mon, 31 Dec 2018 09:24:06 UTC +00:00, 4306],
[Sat, 05 Jan 2019 09:04:50 UTC +00:00, 4308],
[Tue, 01 Jan 2019 11:26:04 UTC +00:00, 4306],
[Wed, 02 Jan 2019 17:24:19 UTC +00:00, 4305]]
Any help appreciated.
Thanks
I suggest using Enumerable#minmax_by to get the min and the max value in just one method call:
array = [['Sun, 30 Dec 2018 15:03:55 UTC +00:00', 4305],['Sun, 30 Dec 2018 15:05:42 UTC +00:00', 4305],['Mon, 31 Dec 2018 09:24:06 UTC +00:00', 4306],['Sat, 05 Jan 2019 09:04:50 UTC +00:00', 4308],['Tue, 01 Jan 2019 11:26:04 UTC +00:00', 4306],['Wed, 02 Jan 2019 17:24:19 UTC +00:00', 4305]]
array.minmax_by(&:last)
#=> [["Sun, 30 Dec 2018 15:03:55 UTC +00:00", 4305], ["Sat, 05 Jan 2019 09:04:50 UTC +00:00", 4308]]
By default when you sort an array sorts by the first element first.
You can reverse the array for the purposes of the sort.
channel_counts_for_history_graph.map(&:reverse).max[0]
I may guess that this is what you were asking for:
[{ created_at: Date.new(2017, 1, 1) }, { created_at: Date.new(2019, 1, 1) }, { created_at: Date.new(2018, 1, 1) }]
.minmax_by { |value| value[:created_at] }

#Tansactional and #Aspect ordering

I would like to execute my code just before #Transactional transaction is started.
#Aspect
#Order(Ordered.HIGHEST_PRECEDENCE)
//#Order(Ordered.LOWEST_PRECEDENCE)
public class SynchronizerAspect {
#Pointcut("execution(public * xxx.xxx.services.*.*(..))")
private void anyServiceOperation() {
}
#Around("anyServiceOperation()")
public Object synchronizerAdvice(ProceedingJoinPoint joinPoint) throws Throwable {
System.out.println("Synchronizing : " + joinPoint.getSignature().getName());
return joinPoint.proceed();
}
When I call a service method marked as #Transactional I always have my aspect code executed inside the transaction:
[INFO] INFO: FETCH created: Fri Oct 30 15:43:11 UTC 2015 duration: 0 connection: 40 statement: 999 resultset: 0
[INFO] paĹş 30, 2015 3:43:11 PM com.mysql.jdbc.log.Slf4JLogger logInfo
[INFO] INFO: QUERY created: Fri Oct 30 15:43:11 UTC 2015 duration: 1 connection: 40 statement: 14 resultset: 15 message: SELECT ##session.tx_isolation
[INFO] paĹş 30, 2015 3:43:11 PM com.mysql.jdbc.log.Slf4JLogger logInfo
[INFO] INFO: FETCH created: Fri Oct 30 15:43:11 UTC 2015 duration: 3 connection: 40 statement: 14 resultset: 15
[INFO] paĹş 30, 2015 3:43:11 PM com.mysql.jdbc.log.Slf4JLogger logInfo
[INFO] INFO: QUERY created: Fri Oct 30 15:43:11 UTC 2015 duration: 1 connection: 40 statement: 999 resultset: 0 message: SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED
[INFO] paĹş 30, 2015 3:43:11 PM com.mysql.jdbc.log.Slf4JLogger logInfo
[INFO] INFO: FETCH created: Fri Oct 30 15:43:11 UTC 2015 duration: 0 connection: 40 statement: 999 resultset: 0
[INFO] paĹş 30, 2015 3:43:11 PM com.mysql.jdbc.log.Slf4JLogger logInfo
[INFO] INFO: QUERY created: Fri Oct 30 15:43:11 UTC 2015 duration: 0 connection: 40 statement: 15 resultset: 16 message: SELECT 1
[INFO] paĹş 30, 2015 3:43:11 PM com.mysql.jdbc.log.Slf4JLogger logInfo
[INFO] INFO: FETCH created: Fri Oct 30 15:43:11 UTC 2015 duration: 3 connection: 40 statement: 15 resultset: 16
[INFO] Synchronizing : getCompany
I also set #EnableTransactionManagement(order = 500)
Is there something that I should done to make it working?
Additionally, I use aspectj-maven-plugin:1.7 to weave aspects at the compile time.
Is it so smart and also uses #Ordering?
It doesn't matter how I set #Order aspectj-maven-plugin logs shows that my #Aspect was added before #Transactional
[INFO] Join point 'method-execution(boolean xxx.xxx.services.LicenseServiceImpl.checkLicenseFile(int, int))' in Type 'xxx.xxx.services.LicenseServiceImpl' (LicenseServiceImpl.java:261) advised by around advice from 'xxx.xxx.aop.SynchronizerAspect' (SynchronizerAspect.java:29)
[INFO] Join point 'method-execution(boolean xxx.xxx.services.LicenseServiceImpl.checkLicenseFile(int, int))' in Type 'xxx.xxx.services.LicenseServiceImpl' (LicenseServiceImpl.java:261) advised by around advice from 'org.springframework.transaction.aspectj.AnnotationTransactionAspect' (spring-aspects-4.2.2.RELEASE.jar!AbstractTransactionAspect.class:66(from AbstractTransactionAspect.aj))
OK. I know the answer:
If Spring's proxy-based AOP is used, #Order annotation works fine.
For load-time weaving it is needed to declare aspect precedence:
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.DeclarePrecedence;
#Aspect
#DeclarePrecedence("xxx.xxx.aop.SynchronizerAspect, org.springframework.transaction.aspectj.AnnotationTransactionAspect, *")
public class AspectPrecedence {
// empty
}
To switch from AutoProxy(default) to AspectJ:
#EnableAspectJAutoProxy
#EnableTransactionManagement(mode = AdviceMode.ASPECTJ)

Inbound emails using webhook with Mandrill Ruby

According to the documentation, we should be looking at a parameter called "message", which doesn't not come in. What does come in is a parameter called "mandrill_events".
require 'mail'
class InboxController < ApplicationController
skip_before_filter :verify_authenticity_token, only: :create
def create
mail = Mail.new(params[:message])
....
No dice, but I do see this in the console log when I use the following syntax (note, it's so much JSON that SO has trouble viewing it with formatting):
puts JSON.parse(params[:mandrill_events])
{"mandrill_events"=>"[{\"event\":\"inbound\",\"ts\":1426188360,\"msg\":{\"raw_msg\":\"Received: from mail-ob0-f181.google.com (unknown [209.85.214.181])\\n\\tby ip-10-39-136-77 (Postfix) with ESMTPS id 25B0E2C0509\\n\\tfor <test#inbound.diabetesdelivery.com>; Thu, 12 Mar 2015 19:26:00 +0000 (UTC)\\nReceived: by obcvb8 with SMTP id vb8so16123307obc.10\\n for <test#inbound.diabetesdelivery.com>; Thu, 12 Mar 2015 12:25:59 -0700 (PDT)\\nDKIM-Signature: v=1; a=rsa-sha256; c=relaxed\\/relaxed;\\n d=gmail.com; s=20120113;\\n h=mime-version:date:message-id:subject:from:to:content-type;\\n bh=jyd6a9aMNBrnuDpbsOEokXnACKw\\/lLnh72zkG7LCs3c=;\\n b=wzt6xiplBtL6dq7uGR8RV6tRR9Lcsmj5zmIktZ7KXFcxbwezN+uEhK\\/XFw6ZjIfhp6\\n LVoEH5ljLjOwK4X4nrtHaPoNzHZizwQUzxk0qXGabTXHW6tqOLZUs3FeDwtt2ekeLvlb\\n bDuU4VcBnNZ5VkXDpA5hQeysCfGECBilAtMy\\/EBjdOngcgk4Fsp8u11\\/eeB2xqBPUcrR\\n JYeu\\/99XossdoeJW3avfxFDBw7ngc98oRS2ZPpyL7MY36XoCZCM25U9ue9kBcJ82n92i\\n ctbNdl+9ikVPdcmUokI0WIvBIBGl5yAcrvOQffxmaTz0c31fkq8+iyprDMP\\/GexVfQzN\\n SAKA==\\nMIME-Version: 1.0\\nX-Received: by 10.202.89.135 with SMTP id n129mr34093639oib.60.1426188359432;\\n Thu, 12 Mar 2015 12:25:59 -0700 (PDT)\\nReceived: by 10.60.119.68 with HTTP; Thu, 12 Mar 2015 12:25:59 -0700 (PDT)\\nDate: Thu, 12 Mar 2015 12:25:59 -0700\\nMessage-ID: <CAMf1_47jvgW6QMwDx8R9JU6C5YiUMaPjvFz3muxhM5v4HJyoSg#mail.gmail.com>\\nSubject: Subject FTW?\\nFrom: Dee diabetic <Deediabetic#gmail.com>\\nTo: test#inbound.diabetesdelivery.com\\nContent-Type: multipart\\/alternative; boundary=001a113d39288bfe8505111c5a88\\n\\n--001a113d39288bfe8505111c5a88\\nContent-Type: text\\/plain; charset=UTF-8\\n\\nBody here\\n\\n--001a113d39288bfe8505111c5a88\\nContent-Type: text\\/html; charset=UTF-8\\n\\n<div dir=\\\"ltr\\\">Body here<\\/div>\\n\\n--001a113d39288bfe8505111c5a88--\",\"headers\":{\"Received\":[\"from mail-ob0-f181.google.com (unknown [209.85.214.181]) by ip-10-39-136-77 (Postfix) with ESMTPS id 25B0E2C0509 for <test#inbound.diabetesdelivery.com>; Thu, 12 Mar 2015 19:26:00 +0000 (UTC)\",\"by obcvb8 with SMTP id vb8so16123307obc.10 for <test#inbound.diabetesdelivery.com>; Thu, 12 Mar 2015 12:25:59 -0700 (PDT)\",\"by 10.60.119.68 with HTTP; Thu, 12 Mar 2015 12:25:59 -0700 (PDT)\"],\"Dkim-Signature\":\"v=1; a=rsa-sha256; c=relaxed\\/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=jyd6a9aMNBrnuDpbsOEokXnACKw\\/lLnh72zkG7LCs3c=; b=wzt6xiplBtL6dq7uGR8RV6tRR9Lcsmj5zmIktZ7KXFcxbwezN+uEhK\\/XFw6ZjIfhp6 LVoEH5ljLjOwK4X4nrtHaPoNzHZizwQUzxk0qXGabTXHW6tqOLZUs3FeDwtt2ekeLvlb bDuU4VcBnNZ5VkXDpA5hQeysCfGECBilAtMy\\/EBjdOngcgk4Fsp8u11\\/eeB2xqBPUcrR JYeu\\/99XossdoeJW3avfxFDBw7ngc98oRS2ZPpyL7MY36XoCZCM25U9ue9kBcJ82n92i ctbNdl+9ikVPdcmUokI0WIvBIBGl5yAcrvOQffxmaTz0c31fkq8+iyprDMP\\/GexVfQzN SAKA==\",\"Mime-Version\":\"1.0\",\"X-Received\":\"by 10.202.89.135 with SMTP id n129mr34093639oib.60.1426188359432; Thu, 12 Mar 2015 12:25:59 -0700 (PDT)\",\"Date\":\"Thu, 12 Mar 2015 12:25:59 -0700\",\"Message-Id\":\"<CAMf1_47jvgW6QMwDx8R9JU6C5YiUMaPjvFz3muxhM5v4HJyoSg#mail.gmail.com>\",\"Subject\":\"Subject FTW?\",\"From\":\"Dee diabetic <Deediabetic#gmail.com>\",\"To\":\"test#inbound.diabetesdelivery.com\",\"Content-Type\":\"multipart\\/alternative; boundary=001a113d39288bfe8505111c5a88\"},\"text\":\"Body here\\n\\n\",\"text_flowed\":false,\"html\":\"<div dir=\\\"ltr\\\">Body here<\\/div>\\n\\n\",\"from_email\":\"Deediabetic#gmail.com\",\"from_name\":\"Dee diabetic\",\"to\":[[\"test#inbound.diabetesdelivery.com\",null]],\"subject\":\"Subject FTW?\",\"spf\":{\"result\":\"pass\",\"detail\":\"sender SPF authorized\"},\"spam_report\":{\"score\":0.5,\"matched_rules\":[{\"name\":\"RCVD_IN_DNSWL_LOW\",\"score\":-0.7,\"description\":\"RBL: Sender listed at http:\\/\\/www.dnswl.org\\/, low\"},{\"name\":null,\"score\":0,\"description\":null},{\"name\":\"listed\",\"score\":0,\"description\":\"in list.dnswl.org]\"},{\"name\":\"FREEMAIL_FROM\",\"score\":0,\"description\":\"Sender email is commonly abused enduser mail provider\"},{\"name\":\"HTML_MESSAGE\",\"score\":0,\"description\":\"BODY: HTML included in message\"},{\"name\":\"DKIM_VALID_AU\",\"score\":-0.1,\"description\":\"Message has a valid DKIM or DK signature from author's\"},{\"name\":\"DKIM_SIGNED\",\"score\":0.1,\"description\":\"Message has a DKIM or DK signature, not necessarily valid\"},{\"name\":\"DKIM_VALID\",\"score\":-0.1,\"description\":\"Message has at least one valid DKIM or DK signature\"},{\"name\":\"RDNS_NONE\",\"score\":1.3,\"description\":\"Delivered to internal network by a host with no rDNS\"}]},\"dkim\":{\"signed\":true,\"valid\":true},\"email\":\"test#inbound.diabetesdelivery.com\",\"tags\":[],\"sender\":null,\"template\":null}}]"}
Mar 12 12:26:046666 app/web.1: {"event"=>"inbound", "ts"=>1426188360, "msg"=>{"raw_msg"=>"Received: from mail-ob0-f181.google.com (unknown [209.85.214.181])\n\tby ip-10-39-136-77 (Postfix) with ESMTPS id 25B0E2C0509\n\tfor ; Thu, 12 Mar 2015 19:26:00 +0000 (UTC)\nReceived: by obcvb8 with SMTP id vb8so16123307obc.10\n for ; Thu, 12 Mar 2015 12:25:59 -0700 (PDT)\nDKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=gmail.com; s=20120113;\n h=mime-version:date:message-id:subject:from:to:content-type;\n bh=jyd6a9aMNBrnuDpbsOEokXnACKw/lLnh72zkG7LCs3c=;\n b=wzt6xiplBtL6dq7uGR8RV6tRR9Lcsmj5zmIktZ7KXFcxbwezN+uEhK/XFw6ZjIfhp6\n LVoEH5ljLjOwK4X4nrtHaPoNzHZizwQUzxk0qXGabTXHW6tqOLZUs3FeDwtt2ekeLvlb\n bDuU4VcBnNZ5VkXDpA5hQeysCfGECBilAtMy/EBjdOngcgk4Fsp8u11/eeB2xqBPUcrR\n JYeu/99XossdoeJW3avfxFDBw7ngc98oRS2ZPpyL7MY36XoCZCM25U9ue9kBcJ82n92i\n ctbNdl+9ikVPdcmUokI0WIvBIBGl5yAcrvOQffxmaTz0c31fkq8+iyprDMP/GexVfQzN\n SAKA==\nMIME-Version: 1.0\nX-Received: by 10.202.89.135 with SMTP id n129mr34093639oib.60.1426188359432;\n Thu, 12 Mar 2015 12:25:59 -0700 (PDT)\nReceived: by 10.60.119.68 with HTTP; Thu, 12 Mar 2015 12:25:59 -0700 (PDT)\nDate: Thu, 12 Mar 2015 12:25:59 -0700\nMessage-ID: \nSubject: Subject FTW?\nFrom: Dee diabetic \nTo: test#inbound.diabetesdelivery.com\nContent-Type: multipart/alternative; boundary=001a113d39288bfe8505111c5a88\n\n--001a113d39288bfe8505111c5a88\nContent-Type: text/plain; charset=UTF-8\n\nBody here\n\n--001a113d39288bfe8505111c5a88\nContent-Type: text/html; charset=UTF-8\n\nBody here\n\n--001a113d39288bfe8505111c5a88--", "headers"=>{"Received"=>["from mail-ob0-f181.google.com (unknown [209.85.214.181]) by ip-10-39-136-77 (Postfix) with ESMTPS id 25B0E2C0509 for ; Thu, 12 Mar 2015 19:26:00 +0000 (UTC)", "by obcvb8 with SMTP id vb8so16123307obc.10 for ; Thu, 12 Mar 2015 12:25:59 -0700 (PDT)", "by 10.60.119.68 with HTTP; Thu, 12 Mar 2015 12:25:59 -0700 (PDT)"], "Dkim-Signature"=>"v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=jyd6a9aMNBrnuDpbsOEokXnACKw/lLnh72zkG7LCs3c=; b=wzt6xiplBtL6dq7uGR8RV6tRR9Lcsmj5zmIktZ7KXFcxbwezN+uEhK/XFw6ZjIfhp6 LVoEH5ljLjOwK4X4nrtHaPoNzHZizwQUzxk0qXGabTXHW6tqOLZUs3FeDwtt2ekeLvlb bDuU4VcBnNZ5VkXDpA5hQeysCfGECBilAtMy/EBjdOngcgk4Fsp8u11/eeB2xqBPUcrR JYeu/99XossdoeJW3avfxFDBw7ngc98oRS2ZPpyL7MY36XoCZCM25U9ue9kBcJ82n92i ctbNdl+9ikVPdcmUokI0WIvBIBGl5yAcrvOQffxmaTz0c31fkq8+iyprDMP/GexVfQzN SAKA==", "Mime-Version"=>"1.0", "X-Received"=>"by 10.202.89.135 with SMTP id n129mr34093639oib.60.1426188359432; Thu, 12 Mar 2015 12:25:59 -0700 (PDT)", "Date"=>"Thu, 12 Mar 2015 12:25:59 -0700", "Message-Id"=>"", "Subject"=>"Subject FTW?", "From"=>"Dee diabetic ", "To"=>"test#inbound.diabetesdelivery.com", "Content-Type"=>"multipart/alternative; boundary=001a113d39288bfe8505111c5a88"}, "text"=>"Body here\n\n", "text_flowed"=>false, "html"=>"Body here\n\n", "from_email"=>"Deediabetic#gmail.com", "from_name"=>"Dee diabetic", "to"=>[["test#inbound.diabetesdelivery.com", nil]], "subject"=>"Subject FTW?", "spf"=>{"result"=>"pass", "detail"=>"sender SPF authorized"}, "spam_report"=>{"score"=>0.5, "matched_rules"=>[{"name"=>"RCVD_IN_DNSWL_LOW", "score"=>-0.7, "description"=>"RBL: Sender listed at http://www.dnswl.org/, low"}, {"name"=>nil, "score"=>0, "description"=>nil}, {"name"=>"listed", "score"=>0, "description"=>"in list.dnswl.org]"}, {"name"=>"FREEMAIL_FROM", "score"=>0, "description"=>"Sender email is commonly abused enduser mail provider"}, {"name"=>"HTML_MESSAGE", "score"=>0, "description"=>"BODY: HTML included in message"}, {"name"=>"DKIM_VALID_AU", "score"=>-0.1, "description"=>"Message has a valid DKIM or DK signature from author's"}, {"name"=>"DKIM_SIGNED", "score"=>0.1, "description"=>"Message has a DKIM or DK signature, not necessarily valid"}, {"name"=>"DKIM_VALID", "score"=>-0.1, "description"=>"Message has at least one valid DKIM or DK signature"}, {"name"=>"RDNS_NONE", "score"=>1.3, "description"=>"Delivered to internal network by a host with no rDNS"}]}, "dkim"=>{"signed"=>true, "valid"=>true}, "email"=>"test#inbound.diabetesdelivery.com", "tags"=>[], "sender"=>nil, "template"=>nil}}
So I am getting a JSON string, but how exactly is the best way to grab the TO, FROM, and SUBJECT?
Update: I just tried the following:
tester = JSON.parse(params[:mandrill_events])
puts tester[:msg][:subject]
#and even this
puts tester["msg"]["subject"]
Did not work. Got an error: **TypeError (no implicit conversion of String into Integer): **
After a day of banging my head, I came up with the solution. By the way, accessing the values directly doesn't work. I had to loop into it.
incomingMail = params[:mandrill_events]
mail_from = "Cannot read From"
mail_originally_to = "Cannot read To"
mail_subject = "No subject"
mail_date = ""
mail_body = "No email body"
if incomingMail != nil
incomingMail = JSON.parse(incomingMail)
incomingMail.each do |item|
mail_from = item["msg"]["from_email"]
mail_originally_to = item["msg"]["headers"]["To"]
mail_subject = item["msg"]["subject"]
mail_date = item["msg"]["headers"]["Date"]
mail_body = item["msg"]["text"]
mail_body_html = item["msg"]["html"]
end
#Confirm
else
puts "Email not sent. Parameter invalid."
end

Maven Surefire parallel='both' working the same way as 'methods'

I have three test classes: FirstTest, SecondTest and ThirdTest. This is how FirstTest class looks like:
public class FirstTest {
#Test
public void test() throws InterruptedException {
System.out.println(this.getClass() + " " + new Date());
Thread.sleep(10_000);
}
#Test
public void test2() throws InterruptedException {
System.out.println(this.getClass() + " " + new Date());
Thread.sleep(10_000);
}
#Test
public void test3() throws InterruptedException {
System.out.println(this.getClass() + " " + new Date());
Thread.sleep(10_000);
}
#Test
public void test4() throws InterruptedException {
System.out.println(this.getClass() + " " + new Date());
Thread.sleep(15_000);
}
}
SecondTest class is identical (10s+10s+10s+15s = 45s total), and ThirdTest contains 10s+10s+10s test methods.
I'm using Maven Surefire plugin with following configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<configuration>
<excludes>
<exclude>${excludeTestPath}</exclude>
</excludes>
<parallel>both</parallel>
<threadCount>20</threadCount>
</configuration>
</plugin>
I'm having problem with understanding how parallel attribute works. I've tried setting "both", "methods" and "classes" values, but got some confusing output. Please, have a look and explain it to me:
parallel='classes'
Concurrency config is parallel='classes', perCoreThreadCount=true,
threadCount=20, useUnlimitedThreads=false
Running experiment.ThirdTest
class experiment.ThirdTest Mon Jun 10 12:00:38 CEST 2013
class experiment.ThirdTest Mon Jun 10 12:00:48 CEST 2013
class experiment.ThirdTest Mon Jun 10 12:00:58 CEST 2013
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 30.024 sec
Running experiment.SecondTest
class experiment.SecondTest Mon Jun 10 12:00:38 CEST 2013
class experiment.SecondTest Mon Jun 10 12:00:48 CEST 2013
class experiment.SecondTest Mon Jun 10 12:00:58 CEST 2013
class experiment.SecondTest Mon Jun 10 12:01:08 CEST 2013
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 45.054 sec
Running experiment.FirstTest
class experiment.FirstTest Mon Jun 10 12:00:38 CEST 2013
class experiment.FirstTest Mon Jun 10 12:00:48 CEST 2013
class experiment.FirstTest Mon Jun 10 12:00:58 CEST 2013
class experiment.FirstTest Mon Jun 10 12:01:08 CEST 2013
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 45.074 sec
Results :
Tests run: 11, Failures: 0, Errors: 0, Skipped: 0
[INFO] Total time: 52.319s
[INFO] Finished at: Mon Jun 10 12:01:48 CEST 2013
[INFO] Final Memory: 22M/354M
This is expected result, three classes were executed parallel, all starting at 12:00:38. Build should take 10s+10s+10s+15s, so about 45s.
parallel='methods'
Concurrency config is parallel='methods', perCoreThreadCount=true,
threadCount=20, useUnlimitedThreads=false
Running experiment.FirstTest
class experiment.FirstTest Mon Jun 10 12:10:23 CEST 2013
class experiment.FirstTest Mon Jun 10 12:10:23 CEST 2013
class experiment.FirstTest Mon Jun 10 12:10:23 CEST 2013
class experiment.FirstTest Mon Jun 10 12:10:23 CEST 2013
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 45.142 sec
Running experiment.SecondTest
class experiment.SecondTest Mon Jun 10 12:10:38 CEST 2013
class experiment.SecondTest Mon Jun 10 12:10:38 CEST 2013
class experiment.SecondTest Mon Jun 10 12:10:38 CEST 2013
class experiment.SecondTest Mon Jun 10 12:10:38 CEST 2013
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 45.037 sec
Running experiment.ThirdTest
class experiment.ThirdTest Mon Jun 10 12:10:53 CEST 2013
class experiment.ThirdTest Mon Jun 10 12:10:53 CEST 2013
class experiment.ThirdTest Mon Jun 10 12:10:53 CEST 2013
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 30.009 sec
Results :
Tests run: 11, Failures: 0, Errors: 0, Skipped: 0
[INFO] Total time: 47.405s
[INFO] Finished at: Mon Jun 10 12:11:04 CEST 2013
[INFO] Final Memory: 22M/354M
This is expected result, all methods were executed parallel within single class. Build should take 15s+15s+10s, so about 45s.
parallel='both'
Concurrency config is parallel='both', perCoreThreadCount=true,
threadCount=20, useUnlimitedThreads=false
Running experiment.FirstTest
class experiment.FirstTest Mon Jun 10 12:18:40 CEST 2013
class experiment.FirstTest Mon Jun 10 12:18:40 CEST 2013
class experiment.FirstTest Mon Jun 10 12:18:40 CEST 2013
class experiment.FirstTest Mon Jun 10 12:18:40 CEST 2013
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 45.18 sec
Running experiment.SecondTest
class experiment.SecondTest Mon Jun 10 12:18:55 CEST 2013
class experiment.SecondTest Mon Jun 10 12:18:55 CEST 2013
class experiment.SecondTest Mon Jun 10 12:18:55 CEST 2013
class experiment.SecondTest Mon Jun 10 12:18:55 CEST 2013
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 45.031 sec
Running experiment.ThirdTest
class experiment.ThirdTest Mon Jun 10 12:19:10 CEST 2013
class experiment.ThirdTest Mon Jun 10 12:19:10 CEST 2013
class experiment.ThirdTest Mon Jun 10 12:19:10 CEST 2013
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 30.025 sec
Results :
Tests run: 11, Failures: 0, Errors: 0, Skipped: 0
[INFO] Total time: 47.521s
[INFO] Finished at: Mon Jun 10 12:19:20 CEST 2013
[INFO] Final Memory: 22M/354M
Now, this one is confusing for me. The build took about 45s, while it should take about 15s (longest test method). Why didn't all three classes start executing at 12:18:40? Doesn't parallel='both' mean that both classes and methods are executed at the same time?
EDIT:
I've found blogpost that mentions the issue.
See this comment from SUREFIRE-814 (from Jan. 2012):
"both" is largely untested for a long time and I have no reason to disbelieve that you're seeing this issue.
It's a safe bet that parallel=both has not received much attention in the interim. I verified that the issue affects Surefire 2.15 and I plan to comment as such and vote on the ticket (as soon as I get my signup confirmation). I recommend more people vote on the ticket.
This issue is fixed in 2.16.
Similar issues should work properly as well
https://issues.apache.org/jira/browse/SUREFIRE-797

Resources