Skip to content

Commit 947b221

Browse files
authored
use timestamp + skip failing linux test (#576)
1 parent d118d28 commit 947b221

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

test/Integration/SqlOutputBindingIntegrationTests.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ public void AddProductArrayTest(SupportedLanguages lang)
114114
/// <param name="lang">The language to run the test against</param>
115115
[Theory]
116116
[SqlInlineData()]
117-
[UnsupportedLanguages(SupportedLanguages.PowerShell, SupportedLanguages.OutOfProc)]
117+
// Java issue: https://github.com/Azure/azure-functions-sql-extension/issues/521
118+
[UnsupportedLanguages(SupportedLanguages.Java, SupportedLanguages.PowerShell, SupportedLanguages.OutOfProc)]
118119
public void AddProductColumnTypesTest(SupportedLanguages lang)
119120
{
120121
this.StartFunctionHost(nameof(AddProductColumnTypes), lang, true);

test/Integration/test-java/src/main/java/com/function/AddProductColumnTypes.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import com.microsoft.azure.functions.sql.annotation.SQLOutput;
1818
import com.function.Common.ProductColumnTypes;
1919

20-
import java.sql.Date;
20+
import java.sql.Timestamp;
2121
import java.util.Optional;
2222

2323
public class AddProductColumnTypes {
@@ -37,8 +37,8 @@ public HttpResponseMessage run(
3737

3838
ProductColumnTypes p = new ProductColumnTypes(
3939
Integer.parseInt(request.getQueryParameters().get("productId")),
40-
new Date(System.currentTimeMillis()),
41-
new Date(System.currentTimeMillis()));
40+
new Timestamp(System.currentTimeMillis()),
41+
new Timestamp(System.currentTimeMillis()));
4242
product.setValue(p);
4343

4444
// Items were inserted successfully so return success, an exception would be thrown if there

test/Integration/test-java/src/main/java/com/function/Common/ProductColumnTypes.java

+12-8
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
package com.function.Common;
88

9-
import java.sql.Date;
9+
import java.sql.Timestamp;
1010

1111
public class ProductColumnTypes {
1212
private int ProductId;
13-
private Date Datetime;
14-
private Date Datetime2;
13+
private Timestamp Datetime;
14+
private Timestamp Datetime2;
1515

16-
public ProductColumnTypes(int productId, Date datetime, Date datetime2) {
16+
public ProductColumnTypes(int productId, Timestamp datetime, Timestamp datetime2) {
1717
ProductId = productId;
1818
Datetime = datetime;
1919
Datetime2 = datetime2;
@@ -23,19 +23,23 @@ public int getProductId() {
2323
return ProductId;
2424
}
2525

26-
public Date getDatetime() {
26+
public void setProductId(int productId) {
27+
ProductId = productId;
28+
}
29+
30+
public Timestamp getDatetime() {
2731
return Datetime;
2832
}
2933

30-
public void setDatetime(Date datetime) {
34+
public void setDatetime(Timestamp datetime) {
3135
Datetime = datetime;
3236
}
3337

34-
public Date getDatetime2() {
38+
public Timestamp getDatetime2() {
3539
return Datetime2;
3640
}
3741

38-
public void setDatetime2(Date datetime2) {
42+
public void setDatetime2(Timestamp datetime2) {
3943
Datetime2 = datetime2;
4044
}
4145
}

test/Integration/test-java/src/main/java/com/function/GetProductsColumnTypesSerialization.java

+8
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import java.text.SimpleDateFormat;
2323
import java.util.Optional;
2424
import java.util.logging.Level;
25+
import java.util.Calendar;
26+
import java.sql.Timestamp;
2527

2628
public class GetProductsColumnTypesSerialization {
2729
@FunctionName("GetProductsColumnTypesSerialization")
@@ -44,6 +46,12 @@ public HttpResponseMessage run(
4446
SimpleDateFormat df = new SimpleDateFormat("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'SSSXXX");
4547
mapper.setDateFormat(df);
4648
for (ProductColumnTypes product : products) {
49+
// Convert the datetimes to UTC (Java worker returns the datetimes in local timezone)
50+
long datetime = product.getDatetime().getTime();
51+
long datetime2 = product.getDatetime2().getTime();
52+
int offset = Calendar.getInstance().getTimeZone().getOffset(product.getDatetime().getTime());
53+
product.setDatetime(new Timestamp(datetime - offset));
54+
product.setDatetime2(new Timestamp(datetime2 - offset));
4755
context.getLogger().log(Level.INFO, mapper.writeValueAsString(product));
4856
}
4957
return request.createResponseBuilder(HttpStatus.OK).header("Content-Type", "application/json").body(mapper.writeValueAsString(products)).build();

0 commit comments

Comments
 (0)