-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Smoke Tests Codegen Working #3155
Changes from 1 commit
feeaccd
76ef3f9
f877902
ae0b5b2
1bba920
4dec4b3
fbfb5c6
18f0386
4b5a7f0
0233376
346c1f0
dc6da8d
fb8414b
872c19b
049a36d
320e03d
5ca8987
6b97b8c
785f364
1273eb9
97e4f61
cbad9dc
b49ca3a
ac1b079
9cb4e54
d44f0eb
7a3f507
f16a2c1
b8bc77f
1cf31c7
d3100ca
f9852cb
5ae8434
03cf379
b27da0e
31c8317
0c96460
3f9f29b
c75a2d7
efa5bb4
1be4d61
b27e018
e1c9608
febfcaf
c1a3350
aec431a
d336778
d2c23a6
b599f31
90f1772
69600c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,23 +51,51 @@ public class SmokeTestsParser implements Runnable{ | |
final private SmithyCodegenAdapter codegenAdapter; | ||
final private PluginContext context; | ||
final private SymbolProvider symbolProvider; | ||
final private Map<ShapeId, String> operationToServiceMap; | ||
final private Map<String, ServiceShape> serviceShapeMap; | ||
|
||
public SmokeTestsParser(PluginContext context) | ||
{ | ||
this.context = context; | ||
this.model = context.getModel(); | ||
codegenAdapter = new SmithyCodegenAdapter(model); | ||
this.codegenAdapter = new SmithyCodegenAdapter(model); | ||
this.symbolProvider = new CppSymbolVisitor(model); | ||
|
||
|
||
operationToServiceMap = new HashMap<>(); | ||
serviceShapeMap = new HashMap<>(); | ||
|
||
// Iterate over all Service shapes in the model and create map of operation to | ||
model.getServiceShapes().stream().forEach(serviceShape -> { | ||
String serviceName = serviceShape.getId().getName(); | ||
serviceShape.getAllOperations().stream().forEach(operation -> { | ||
this.operationToServiceMap.put( operation, serviceName); | ||
this.serviceShapeMap.put(serviceName,serviceShape ); | ||
}); | ||
}); | ||
} | ||
|
||
private String getServiceName(ShapeId serviceShapeId) | ||
public static String removeSpaces(String input) | ||
{ | ||
String clientName = serviceShapeId.getName(); | ||
System.out.println("clientName="+clientName); | ||
return input.replace(" ", ""); | ||
} | ||
|
||
public static String toKebabCase(String input) { | ||
// Remove leading and trailing spaces, replace spaces with hyphens, and convert to lowercase | ||
return input.trim().toLowerCase().replace(" ", "-"); | ||
} | ||
|
||
private String getServiceName(ServiceShape serviceShape) throws Exception | ||
{ | ||
if(!serviceShape.getTrait(ServiceTrait.class).isPresent()) | ||
{ | ||
//System.err.println(String.format("No service trait detected in service shape with name=%s",serviceShape.getId().getName())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove commented out code There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ack |
||
throw new Exception(String.format("No service trait detected in service shape with name=%s",serviceShape.getId().getName())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dont throw exception, everyon up chain has to check it, never throw or check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is your recommendation how I should handle this? I understand that stack unwinding will happen on exception but what do i return when service trait is missing. I can throw a Runtimeexception There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. they have a concept of "checked and unchecked exceptions" in java. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ack. I will switch to runtime exception as it is one of those cases where I have to throw if service trait not found |
||
} | ||
|
||
//this.model.getShape(serviceShapeId) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove commented out code There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ack There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. still commented out There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ack. Oversight |
||
String clientName = serviceShape.getTrait(ServiceTrait.class).get().getSdkId(); | ||
|
||
int underscoreIndex = clientName.indexOf('_'); | ||
// Check if underscore exists, otherwise return the whole string | ||
clientName = underscoreIndex != -1 ? clientName.substring(0, underscoreIndex) : clientName; | ||
return clientName; | ||
} | ||
|
||
|
@@ -213,22 +241,9 @@ else if(serviceShape.getTrait(HttpBearerAuthTrait.class).isPresent()) | |
|
||
//model contains information from all the smithy files | ||
//extract services to smoke tests | ||
public Map<ShapeId, List<SmokeTestData> > extractServiceSmokeTests() | ||
public Map<ServiceShape, List<SmokeTestData> > extractServiceSmokeTests() | ||
{ | ||
Map<ShapeId, List<SmokeTestData> > serviceSmokeTestsMap = new HashMap<>(); | ||
|
||
Map<ShapeId, String> operationToServiceMap = new HashMap<>(); | ||
Map<String, ServiceShape> serviceShapeMap = new HashMap<>(); | ||
|
||
// Iterate over all Service shapes in the model and create map of operation to | ||
model.getServiceShapes().stream().forEach(serviceShape -> { | ||
String serviceName = serviceShape.getId().getName(); | ||
serviceShape.getAllOperations().stream().forEach(operation -> { | ||
operationToServiceMap.put( operation, serviceName); | ||
serviceShapeMap.put(serviceName,serviceShape ); | ||
}); | ||
}); | ||
|
||
Map<ServiceShape, List<SmokeTestData> > serviceSmokeTestsMap = new HashMap<>(); | ||
|
||
//first filter operations that have smoke test trait | ||
//on those operation shapes, find service trait | ||
|
@@ -241,9 +256,7 @@ public Map<ShapeId, List<SmokeTestData> > extractServiceSmokeTests() | |
SmokeTestsTrait smokeTestsTrait = operationShape.getTrait(SmokeTestsTrait.class).get(); | ||
//get serviceShape | ||
String serviceName = operationToServiceMap.get(operationShape.getId()); | ||
|
||
ServiceShape serviceShape = serviceShapeMap.get(serviceName); | ||
|
||
System.out.println("OperationShape: " + operationShape.getId().getName()); | ||
System.out.println("serviceName: " + serviceName); | ||
|
||
|
@@ -252,13 +265,13 @@ public Map<ShapeId, List<SmokeTestData> > extractServiceSmokeTests() | |
operationShape, | ||
serviceShape ); | ||
//add to tests for the same service | ||
if(serviceSmokeTestsMap.containsKey(serviceShape.getId())) | ||
if(serviceSmokeTestsMap.containsKey(serviceShape)) | ||
{ | ||
serviceSmokeTestsMap.get(serviceShape.getId()).addAll(tests); | ||
serviceSmokeTestsMap.get(serviceShape).addAll(tests); | ||
} | ||
else | ||
{ | ||
serviceSmokeTestsMap.put(serviceShape.getId(), tests); | ||
serviceSmokeTestsMap.put(serviceShape, tests); | ||
} | ||
|
||
}); | ||
|
@@ -274,23 +287,31 @@ public void run(){ | |
SmokeTestsSourceDelegator delegator = new SmokeTestsSourceDelegator(this.context.getFileManifest(), this.symbolProvider); | ||
SmokeTestsCMakeDelegator cmakedelegator = new SmokeTestsCMakeDelegator(this.context.getFileManifest(), this.symbolProvider); | ||
|
||
Map<ShapeId, List<SmokeTestData> > smoketests = extractServiceSmokeTests(); | ||
Map<ServiceShape, List<SmokeTestData> > smoketests = extractServiceSmokeTests(); | ||
|
||
//make service specific folder | ||
smoketests.entrySet().stream().forEach(entry -> { | ||
String serviceName = getServiceName(entry.getKey()); | ||
Path relativePath = Paths.get( serviceName ); | ||
System.out.println(String.format("path=%s",relativePath.toString() + "/"+ serviceName + "SmokeTests.cpp")); | ||
|
||
delegator.useFileWriter( relativePath.toString() + "/"+ getServiceName(entry.getKey()) + "SmokeTests.cpp", serviceName, writer -> { | ||
System.out.println("generating smoke test source code"); | ||
writer.generate(entry.getValue()); | ||
}); | ||
|
||
cmakedelegator.useFileWriter( relativePath.toString() + "/"+ "CMakeLists.txt", serviceName, writer -> { | ||
System.out.println("generating smoke test cmake code"); | ||
writer.generate(); | ||
}); | ||
ServiceShape serviceShape = entry.getKey(); | ||
|
||
try{ | ||
String client = getServiceName(serviceShape); | ||
|
||
Path relativePath = Paths.get( toKebabCase(client) ); | ||
System.out.println(String.format("path=%s",relativePath.toString() + "/"+ removeSpaces(client) + "SmokeTests.cpp")); | ||
|
||
delegator.useFileWriter( relativePath.toString() + "/"+ removeSpaces(client) + "SmokeTests.cpp", client, writer -> { | ||
System.out.println("generating smoke test source code"); | ||
writer.generate(entry.getValue()); | ||
}); | ||
|
||
cmakedelegator.useFileWriter( relativePath.toString() + "/"+ "CMakeLists.txt", client, writer -> { | ||
System.out.println("generating smoke test cmake code"); | ||
writer.generate(); | ||
}); | ||
} | ||
catch (Exception e) { | ||
System.err.println("Exception detected=" + e.toString()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove catch or re-throw runtime exception so the generation will actually fail There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ack |
||
} | ||
}); | ||
|
||
delegator.flushWriters(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove commented code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ack. i left this code in case we ever want to auto run smoke tests. I can remove it for now