Commit Graph

383 Commits

Author SHA1 Message Date
Jon Parise
13b3b74773 Add typespecs to various utility functions (#211) 2017-02-07 10:00:29 -08:00
Dan Swain
cbb1e81595 Add values/0 to generated enum module (#189)
* Add `values/0` to generated enum module

This came up with one of my use cases.  Seems a reasonable counterpoint
to `names/0`.

* Change values/names to use meta, add enum functions
2017-02-07 09:59:47 -08:00
Dan Swain
642a7ff794 Merge branch 'thrift_tng' into file_of_consts 2017-02-07 12:59:02 -05:00
Jon Parise
adc9b9ddd9 Introduce a 'serializable' type (#210)
This also lets us address a dialyzer warning because we previously
weren't allowing the :application_exception atom to be serialized.
2017-02-06 17:20:07 -08:00
Jon Parise
ed90a1f6f3 Disable Credo's NoParenthesesWhenZeroArity check (#212)
This appears to crash on some of our code. We'll need to investigation
that separately.
2017-02-06 09:04:48 -08:00
Jon Parise
6b7b518119 Annotate model structs with @enforce_keys (#207)
This provides a simple compile-type guarantee that any required keys
have been specified when constructing these structs.
2017-02-06 05:39:38 -08:00
Jon Parise
b7fb68cd08 Handle unknown (invalid) compiler task options (#209)
We were still using OptionParser.parse!/1 in the compiler task from back
when we also supported interactive usage. Unfortunately, that function
throws an exception when it encounters an unknown (invalid) option.

Instead, we use OptionParser.parse/1, which allows us to safely discard
invalid options.
2017-02-06 05:37:23 -08:00
Dan Swain
1fdcef33b6 Generate constants in a module defined by the file
Instead of in a .Constants module
2017-02-05 21:14:35 -05:00
Dan Swain
9716f44b0d Generate constants as macros 2017-02-04 20:35:09 -05:00
Jon Parise
8a7eafb6aa Upgrade to Credo 0.6.1 (#205)
This lets us restore the specs checker.
2017-02-03 14:32:49 -08:00
Dan Swain
059d3d0587 Generate a t type for structs/unions/exceptions (#204)
It's fairly common to have follow a defstruct with a `@type t`.  This is
useful for dialyzer analysis and writing specs that convey useful
information.
2017-02-01 16:36:05 -08:00
Dan Swain
75aa56acfb Merge branch 'thrift_tng' into file_of_consts 2017-01-30 14:58:04 -06:00
Dan Swain
49c18f545b Alphabeticalize 2017-01-27 10:00:49 -05:00
Preston Guillory
8f1df5f6d5 Allow enum fields to have no default value (#198)
* Allow enum fields to have no default value

* Allow enum fields to have a default value

* Minor refactor
2017-01-26 17:42:09 -08:00
Dan Swain
d9d3dfdaf2 Add test file with only constants defined 2017-01-26 20:22:31 -05:00
Dan Swain
0f7e543a16 Add constant test cases, handle map constant 2017-01-26 20:16:13 -05:00
Dan Swain
6a162a4f05 Generate constants in a <base>.Constants module 2017-01-26 19:26:13 -05:00
Dan Swain
870de631e7 Rename/move default_value to quoted_value
Since it's now used in more than one place.  I'm not convinced that
Utils is the perfect spot for it but nothing else made sence either.
2017-01-26 18:30:03 -05:00
Dan Swain
fe58a6dda6 Merge branch 'thrift_tng' into file_of_consts 2017-01-26 17:18:34 -05:00
Preston Guillory
a0e0a1d9d2 Allow lists to serialize into maps/sets (#199) 2017-01-26 09:39:15 -08:00
Jon Parise
4f4591fa2b Upgrade Credo to version 0.6.0 (#201)
This merges a34861c into master.
2017-01-26 08:55:47 -08:00
Jon Parise
a34861c4b2 Upgrade Credo to version 0.6.0 (#200)
This also disables the "Readability.Specs" check because it appears to
crash Credo when it encounters some of our macro-ized code. That can be
investigated separately.
2017-01-26 08:43:47 -08:00
Jon Parise
b98d2ca4c6 Group compiler options under a :thrift key (#197)
This change moves all compiler options under a single top-level `thrift`
configuration key that contains a Keyword list of individual options.
`thrift_files` and `thrift_output` are now just `files` and `output_path`
within this sub-list.

The goal of this change is to tidy up the top-level configuration space
and provide for further expansion of our compiler option set.
2017-01-26 02:00:01 -08:00
Dan Swain
dabe15fab9 Generate constants modules 2017-01-25 21:04:24 -05:00
Preston Guillory
9a0e20338d Catch name collisions within type (#184)
* Catch name collisions within type

If two names of the same type (for example, two structs) exist in the same
file, one of them will be discarded silently at parse time. This causes it to
raise an exception.

* Clean up exception message
2017-01-23 10:40:05 -08:00
Jon Parise
72632c75a3 Prepare the 1.3.2 release (#187)
This address some remaining Elixir 1.4 warnings, tweaks the docs, and
updates a few package dependencies.
2017-01-18 15:15:47 -08:00
Jon Parise
9d2ce55620 Reintroduce the 'thrift.generate' mix task (#186)
My previous attempt to consolidate these two mix tasks into one was
unsuccessful due to the way mix tasks receive their command line
arguments. Specifically, we don't have a good way to differentiate
between e.g. a `mix test` command line containing test script filenames
and a `mix compile.thrift` command line naming Thrift schema files. When
the `:thrift` compiler is included, it will also run in the `mix test`
task flow and get confused about its inputs.

We now have two distinct and purpose-built mix tasks:

 - `compile.thrift` - intended for use in the Mix.compilers list
 - `thrift.generate` - intended for interactive command-line use
2017-01-17 14:18:58 -08:00
Preston Guillory
4aab8763d2 Convert resolver from process to function (#183)
Previously the resolver was a separate process that just maintained a map. This
had the drawback that it was difficult to catch errors raised during the
resolution process. We'd to be able to raise such an error on name collisions.
2017-01-13 17:47:08 -08:00
Preston Guillory
151fd0c6f1 Support binary default values (#182)
* Support binary default values

* Check binary default value
2017-01-13 15:39:36 -08:00
Jon Parise
aa07d24c5a Consolidate binary protocol field type constants (#180)
We previously defined nearly identical sets of constants representing
the binary protocol's field types as attributes in each module that
required them. This duplication isn't great for long-term maintenance.

This approach defines a single set of type constants as macros in a
new Thrift.Protocol.Binary.Type module. Using macros lets us preserve
all of the compile-time benefits we were getting from the previous
approach while still supporting code sharing.
2017-01-13 13:30:44 -08:00
Jon Parise
39882a2957 Force coveralls.travis to run in the 'test' env (#178) 2017-01-12 10:20:56 -08:00
Preston Guillory
6b4a15f60f Make generated server opts optional (#176) 2017-01-11 13:39:05 -08:00
Steve Cohen
1f78c31055 Timeout / Retry refactor (#167)
* Timeout / Retry refactor

Servers now support read timeouts

Additionally, I changed how we handle retries due to some idiosyncracies
with how erlang responds to server failures.

When the server closes the connection, the client's `:gen_tcp.send`
operation will always succeed, failing instead on the corresponding
`:gen_tcp.recv` command. This is problematic, because we can't know for
sure that a message has been sent, and if we retry, we might resend a
message accidentally.

Furthermore, we can _never_ really know if a oneway message has been
sent or not.

Admittedly, the window for this is pretty narrow, the server would have
to sever the connection between the send and recv calls. The next case
is more troublesome.

Since we have backoff behavior, imagine if the user has set a retry
count of `:infinity` and made a call to a dead server. Now the client is
backing off and the `GenServer` call will timeout after 5 seconds. The
client is now stuck in a loop, reconnecting forever.

In light of these issues, I've removed repeated reconnects from the
client and have implemented a one-shot reconnect. We can still send a
message twice, but the window is sufficiently small to make me not worry
so much. This also has the effect of improving UX in the light of a
server that disconnects clients after a short timeout. If you send a
message on a disconnected client, it remembers it, reconnects and sends
it.

That seems reasonable.
2017-01-11 13:25:15 -08:00
Preston Guillory
c2a1f51475 Wrap long lines in generated output (#175)
Generated module names can be quite long, so this pattern produces very long
lines because Macro.to_string does not wrap pipe operators to the next line.

  serialized_var = %Big.Generated.Module{} |> Big.Generated.Module.serialize()

This change just replaces it with a slightly more readable:

  var = %Big.Generated.Module{}
  Big.GeneratedModule.serialize(var)
2017-01-11 11:47:05 -08:00
Jon Parise
658bf9f878 Use the latest .Client and .Server namespaces (#174)
Fixes #171
2017-01-11 09:08:29 -08:00
Ali Altaf
5d955839f7 Fixed incorrect code in README (#173) 2017-01-10 16:48:44 -08:00
Dan Swain
204254e4f6 Merge pull request #165 from dantswain/field_of_snakes
Ensure field names are valid elixir function names
2017-01-10 11:24:50 -05:00
Steve Cohen
592ff37c5b We moved the behaviour, example now reflects that (#169) 2017-01-09 17:31:47 -08:00
Steve Cohen
087724d5f9 Handled binary type in Behviour (#168)
The behaviour module didn't properly handle the binary type.
2017-01-09 17:31:36 -08:00
Jon Parise
8b1728294f Update dependencies for Elixir 1.4 compatibility (#166)
This are all relatively minor updates to newer releases, many of which
address new Elixir 1.4 warnings.
2017-01-08 10:00:27 -08:00
Dan Swain
e3c1af0056 Comment the atomic snake 2017-01-08 12:58:46 -05:00
Jon Parise
186663d600 Fix some warnings flagged by Elixir 1.4 (#164)
1. Unused module attributes
2. Variable vs. function name ambiguity
2017-01-08 08:57:49 -08:00
Dan Swain
31a2ca8474 Ensure field names are valid elixir function names
Closes #161
2017-01-08 09:31:36 -05:00
Preston Guillory
887be2f8b1 Make client start_link opts optional (#163) 2017-01-06 14:14:02 -08:00
Preston Guillory
abef5d995e Refactor Client generated/static interface (#158)
* Refactor Client generated/static interface

This moves message serialization completely into Binary.Framed.Client, and
response decoding completely out into the generated client. Their
responsibilities are more coherent. It also puts us into position for future
potential improvements, such as moving seq_id management into the connection
process's state, and generating code to match response exceptions in the way we
currently match unions.

* Return TApplicationException for invalid message type

* Keep seq_id in connection process state

* PR feedback
2017-01-06 10:04:00 -08:00
Preston Guillory
5cba75d22c Rename StructRef to TypeRef/ValueRef (#159)
* Rename StructRef to TypeRef/ValueRef

* Rebased onto thrift_tng
2017-01-06 10:03:33 -08:00
Preston Guillory
cc81ac3620 Ignore tmp directory (#160)
The tmp directory is used to store temporary .thrift and generated files by
ThriftTestCase. It's typically around during development and contains files but
they should not be checked in.
2017-01-06 04:34:51 -08:00
Preston Guillory
6bcdb81b1e Implement struct defaults (#154)
* Implement struct defaults

* Test empty defaults
2017-01-05 16:52:44 -08:00
Preston Guillory
a586a1a577 Implement deserialization of maps/sets/lists of binaries (#156)
Seems to have been overlooked. We implemented strings, which are effectively
the same in Elixir, but didn't check specifically for a type of :binary in
every situation.
2017-01-05 16:11:39 -08:00
Steve Cohen
77f22b75dd Server benchmark (#155)
* Added simple server benchmark

Updated README.md with benchmark results
2017-01-05 15:46:49 -08:00